Commit 8115f0b850755b08e4d846ddd8586823d790acca

Authored by Sergio Crisostomo
1 parent c82e714c

fix regex and make empty string go back to old value on change

Showing 1 changed file with 3 additions and 3 deletions   Show diff stats
src/components/input-number/input-number.vue
@@ -254,13 +254,13 @@ @@ -254,13 +254,13 @@
254 change (event) { 254 change (event) {
255 let val = event.target.value.trim(); 255 let val = event.target.value.trim();
256 256
257 - if (event.type == 'input' && val.match(/^\.$|\.$/)) return; // prevent fire early if decimal. If no more input the change event will fire later 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 258 if (event.type == 'change' && Number(val) === this.currentValue) return; // already fired change for input event
259 259
260 const {min, max} = this; 260 const {min, max} = this;
261 - 261 + const isEmptyString = val.length === 0;
262 val = Number(val); 262 val = Number(val);
263 - if (!isNaN(val)) { 263 + if (!isNaN(val) && !isEmptyString) {
264 this.currentValue = val; 264 this.currentValue = val;
265 265
266 if (val > max) { 266 if (val > max) {