Skip to content

Commit 5761652

Browse files
committed
Prevent right-click menus. Added input validation deferral.
1 parent e4a0dbf commit 5761652

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

src/vue-numeric-input.vue

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
@change="onChange"
1616
@blur="onBlur"
1717
@focus="onFocus"
18+
v-on:keyup.enter="$event.target.blur()"
1819
:autofocus="autofocus"
1920
:disabled="disabled"
2021
:readonly="readonly"
@@ -24,6 +25,7 @@
2425
v-if="controls"
2526
class="btn btn-decrement"
2627
@mousedown="start(decrement)"
28+
@contextmenu.prevent
2729
@touchstart="$event.preventDefault(); start(decrement)"
2830
@touchend="$event.preventDefault(); stop($event)"
2931
:disabled="disabled || numericValue <= min"
@@ -35,6 +37,7 @@
3537
v-if="controls"
3638
class="btn btn-increment"
3739
@mousedown="start(increment)"
40+
@contextmenu.prevent
3841
@touchstart="$event.preventDefault(); start(increment)"
3942
@touchend="$event.preventDefault(); stop($event)"
4043
:disabled="disabled || numericValue >= max"
@@ -44,6 +47,7 @@
4447
</div>
4548
</template>
4649
<script>
50+
4751
const timeInterval = 100
4852
4953
export default {
@@ -97,6 +101,11 @@ export default {
97101
controlsType: {
98102
type: String,
99103
default: 'plusminus'
104+
},
105+
106+
delayValidation: {
107+
type: Boolean,
108+
default: false
100109
}
101110
102111
},
@@ -105,7 +114,9 @@ export default {
105114
numericValue: null,
106115
interval: null,
107116
startTime: null,
108-
handler: Function
117+
handler: Function,
118+
deferredValue: null,
119+
backingValue: null,
109120
}
110121
},
111122
watch: {
@@ -169,7 +180,12 @@ export default {
169180
* Handle value on Input
170181
*/
171182
inputHandler (val) {
172-
this.updateValue(this.toNumber(val), val)
183+
if (this.delayValidation) {
184+
this.deferredValue = this.toNumber(val)
185+
}
186+
else {
187+
this.updateValue(this.toNumber(val), val)
188+
}
173189
},
174190
/**
175191
* Update value on operation performed
@@ -189,6 +205,7 @@ export default {
189205
return
190206
}
191207
this.numericValue = val
208+
this.backingValue = val
192209
this.$emit('input', val)
193210
},
194211
/**
@@ -222,13 +239,22 @@ export default {
222239
* @param event - blur event on input
223240
*/
224241
onBlur (event) {
242+
if (this.delayValidation) {
243+
if (isNaN(parseFloat(this.deferredValue))) {
244+
this.updateValue(this.backingValue)
245+
}
246+
else {
247+
this.updateValue(this.deferredValue)
248+
}
249+
}
225250
this.$emit('blur', event)
226251
},
227252
/**
228253
* On focus event trigger on input
229254
* @param event
230255
*/
231256
onFocus (event) {
257+
this.backingValue = this.value
232258
this.$emit('focus', event)
233259
},
234260
/**

0 commit comments

Comments
 (0)