Fixed #506 - Add input event to InputNumber

pull/525/head
mertsincan 2020-09-27 22:10:59 +03:00
parent ba6f6bf7b9
commit 7cf493de03
1 changed files with 28 additions and 4 deletions

View File

@ -1,7 +1,7 @@
<template> <template>
<span :class="containerClass" :style="style"> <span :class="containerClass" :style="style">
<INInputText ref="input" class="p-inputnumber-input" :value="formattedValue" v-bind="$attrs" :aria-valumin="min" :aria-valuemax="max" <INInputText ref="input" class="p-inputnumber-input" :value="formattedValue" v-bind="$attrs" :aria-valumin="min" :aria-valuemax="max"
@input="onInput" @keydown="onInputKeyDown" @keypress="onInputKeyPress" @paste="onPaste" @click="onInputClick" @focus="onInputFocus" @blur="onInputBlur"/> @input="onUserInput" @keydown="onInputKeyDown" @keypress="onInputKeyPress" @paste="onPaste" @click="onInputClick" @focus="onInputFocus" @blur="onInputBlur"/>
<span class="p-inputnumber-button-group" v-if="showButtons && buttonLayout === 'stacked'"> <span class="p-inputnumber-button-group" v-if="showButtons && buttonLayout === 'stacked'">
<INButton :class="upButtonClass" :icon="incrementButtonIcon" v-on="upButtonListeners" :disabled="$attrs.disabled" /> <INButton :class="upButtonClass" :icon="incrementButtonIcon" v-on="upButtonListeners" :disabled="$attrs.disabled" />
<INButton :class="downButtonClass" :icon="decrementButtonIcon" v-on="downButtonListeners" :disabled="$attrs.disabled" /> <INButton :class="downButtonClass" :icon="decrementButtonIcon" v-on="downButtonListeners" :disabled="$attrs.disabled" />
@ -271,6 +271,8 @@ export default {
this.updateInput(newValue, null, 'spin'); this.updateInput(newValue, null, 'spin');
this.updateModel(event, newValue); this.updateModel(event, newValue);
this.handleOnInput(event, currentValue, newValue);
}, },
onUpButtonMouseDown(event) { onUpButtonMouseDown(event) {
this.$refs.input.$el.focus(); this.$refs.input.$el.focus();
@ -310,7 +312,7 @@ export default {
this.repeat(event, null, -1); this.repeat(event, null, -1);
} }
}, },
onInput() { onUserInput() {
if (this.isSpecialChar) { if (this.isSpecialChar) {
this.$refs.input.$el.value = this.lastValue; this.$refs.input.$el.value = this.lastValue;
} }
@ -614,10 +616,32 @@ export default {
this._minusSign.lastIndex = 0; this._minusSign.lastIndex = 0;
}, },
updateValue(event, valueStr, insertedValueStr, operation) { updateValue(event, valueStr, insertedValueStr, operation) {
let currentValue = this.$refs.input.$el.value;
let newValue = null;
if (valueStr != null) { if (valueStr != null) {
let newValue = this.parseValue(valueStr); newValue = this.parseValue(valueStr);
this.updateInput(newValue, insertedValueStr, operation); this.updateInput(newValue, insertedValueStr, operation);
} }
this.handleOnInput(event, currentValue, newValue);
},
handleOnInput(event, currentValue, newValue) {
if (this.isValueChanged(currentValue, newValue)) {
this.$emit('input', { originalEvent: event, value: newValue });
}
},
isValueChanged(currentValue, newValue) {
if (newValue === null && currentValue !== null) {
return true;
}
if (newValue != null) {
let parsedCurrentValue = (typeof currentValue === 'string') ? this.parseValue(currentValue) : currentValue;
return newValue !== parsedCurrentValue;
}
return false;
}, },
validateValue(value) { validateValue(value) {
if (this.min != null && value < this.min) { if (this.min != null && value < this.min) {