diff --git a/src/components/input-number/input-number.vue b/src/components/input-number/input-number.vue index 196515f..638134c 100644 --- a/src/components/input-number/input-number.vue +++ b/src/components/input-number/input-number.vue @@ -24,6 +24,7 @@ @focus="focus" @blur="blur" @keydown.stop="keyDown" + @input="change" @change="change" :readonly="readonly || !editable" :name="name" @@ -38,9 +39,6 @@ const prefixCls = 'ivu-input-number'; const iconPrefixCls = 'ivu-icon'; - function isValueNumber (value) { - return (/(^-?[0-9]+\.{1}\d+$)|(^-?[1-9][0-9]*$)|(^-?0{1}$)/).test(value + ''); - } function addNum (num1, num2) { let sq1, sq2, m; try { @@ -256,11 +254,13 @@ change (event) { let val = event.target.value.trim(); - const max = this.max; - const min = this.min; + if (event.type == 'input' && val.match(/^\.$|\.$/)) return; // prevent fire early if decimal. If no more input the change event will fire later + if (event.type == 'change' && Number(val) === this.currentValue) return; // already fired change for input event + + const {min, max} = this; - if (isValueNumber(val)) { - val = Number(val); + val = Number(val); + if (!isNaN(val)) { this.currentValue = val; if (val > max) { @@ -275,8 +275,8 @@ } }, changeVal (val) { - if (isValueNumber(val) || val === 0) { - val = Number(val); + val = Number(val); + if (!isNaN(val)) { const step = this.step; this.upDisabled = val + step > this.max; -- libgit2 0.21.4