Commit 9ca05a64dab13ac7212d3a161fd44a4c5f808231
Committed by
GitHub
Merge pull request #2059 from SergioCrisostomo/add-input-event
fire change on "input" event
Showing
1 changed file
with
9 additions
and
9 deletions
Show diff stats
src/components/input-number/input-number.vue
@@ -24,6 +24,7 @@ | @@ -24,6 +24,7 @@ | ||
24 | @focus="focus" | 24 | @focus="focus" |
25 | @blur="blur" | 25 | @blur="blur" |
26 | @keydown.stop="keyDown" | 26 | @keydown.stop="keyDown" |
27 | + @input="change" | ||
27 | @change="change" | 28 | @change="change" |
28 | :readonly="readonly || !editable" | 29 | :readonly="readonly || !editable" |
29 | :name="name" | 30 | :name="name" |
@@ -38,9 +39,6 @@ | @@ -38,9 +39,6 @@ | ||
38 | const prefixCls = 'ivu-input-number'; | 39 | const prefixCls = 'ivu-input-number'; |
39 | const iconPrefixCls = 'ivu-icon'; | 40 | const iconPrefixCls = 'ivu-icon'; |
40 | 41 | ||
41 | - function isValueNumber (value) { | ||
42 | - return (/(^-?[0-9]+\.{1}\d+$)|(^-?[1-9][0-9]*$)|(^-?0{1}$)/).test(value + ''); | ||
43 | - } | ||
44 | function addNum (num1, num2) { | 42 | function addNum (num1, num2) { |
45 | let sq1, sq2, m; | 43 | let sq1, sq2, m; |
46 | try { | 44 | try { |
@@ -256,11 +254,13 @@ | @@ -256,11 +254,13 @@ | ||
256 | change (event) { | 254 | change (event) { |
257 | let val = event.target.value.trim(); | 255 | let val = event.target.value.trim(); |
258 | 256 | ||
259 | - const max = this.max; | ||
260 | - const min = this.min; | 257 | + if (event.type == 'input' && val.match(/^\-?\.?$|\.$/)) return; // prevent fire early if decimal. If no more input the change event will fire later |
258 | + if (event.type == 'change' && Number(val) === this.currentValue) return; // already fired change for input event | ||
261 | 259 | ||
262 | - if (isValueNumber(val)) { | ||
263 | - val = Number(val); | 260 | + const {min, max} = this; |
261 | + const isEmptyString = val.length === 0; | ||
262 | + val = Number(val); | ||
263 | + if (!isNaN(val) && !isEmptyString) { | ||
264 | this.currentValue = val; | 264 | this.currentValue = val; |
265 | 265 | ||
266 | if (val > max) { | 266 | if (val > max) { |
@@ -275,8 +275,8 @@ | @@ -275,8 +275,8 @@ | ||
275 | } | 275 | } |
276 | }, | 276 | }, |
277 | changeVal (val) { | 277 | changeVal (val) { |
278 | - if (isValueNumber(val) || val === 0) { | ||
279 | - val = Number(val); | 278 | + val = Number(val); |
279 | + if (!isNaN(val)) { | ||
280 | const step = this.step; | 280 | const step = this.step; |
281 | 281 | ||
282 | this.upDisabled = val + step > this.max; | 282 | this.upDisabled = val + step > this.max; |