From e54d6c01a062dd7677fed589ac8d1ad07303aa5a Mon Sep 17 00:00:00 2001 From: Leonardo Matos Date: Sat, 9 May 2020 02:06:29 -0300 Subject: [PATCH] fix(number-inputs): prevent emitting 0 when empty --- src/components/_inputs/js/InputMoney.js | 7 ++++--- src/components/_inputs/js/InputNumber.js | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/components/_inputs/js/InputMoney.js b/src/components/_inputs/js/InputMoney.js index 4bcaf60..7445aaa 100644 --- a/src/components/_inputs/js/InputMoney.js +++ b/src/components/_inputs/js/InputMoney.js @@ -31,8 +31,9 @@ export default { get () { return this.value }, - set (value) { - this.$emit('input', Number(value)) + set (val) { + const num = parseFloat(val) + this.$emit('input', isNaN(num) ? null : num) } }, @@ -50,7 +51,7 @@ export default { }, mounted () { - if (this.schema.default) { + if (typeof this.schema.default === 'number') { this.localValue = this.schema.default } } diff --git a/src/components/_inputs/js/InputNumber.js b/src/components/_inputs/js/InputNumber.js index ef7a461..960bc05 100644 --- a/src/components/_inputs/js/InputNumber.js +++ b/src/components/_inputs/js/InputNumber.js @@ -32,7 +32,7 @@ export default { }, mounted () { - if (this.schema.default) { + if (typeof this.schema.default === 'number') { this.localValue = this.schema.default } }