Skip to content

Commit

Permalink
Merge pull request #6407 from KumJungMin/fix/issue-6276
Browse files Browse the repository at this point in the history
fix: emit unmask value to update:modelValue when unmask mode
  • Loading branch information
tugcekucukoglu authored Sep 25, 2024
2 parents fdf9c92 + a31c0f2 commit 4e451e7
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions packages/primevue/src/inputmask/InputMask.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<InputText
:id="id"
:value="modelValue"
:value="currentVal"
:class="inputClass"
:readonly="readonly"
:disabled="disabled"
Expand Down Expand Up @@ -37,6 +37,11 @@ export default {
inject: {
$pcFluid: { default: null }
},
data() {
return {
currentVal: ''
};
},
watch: {
mask(newMask, oldMask) {
if (oldMask !== newMask) {
Expand All @@ -60,7 +65,7 @@ export default {
if (this.androidChrome) this.handleAndroidInput(event);
else this.handleInputChange(event);
this.$emit('update:modelValue', event.target.value);
this.updateModelValue(event.target.value);
}
},
onFocus(event) {
Expand Down Expand Up @@ -96,7 +101,7 @@ export default {
onBlur(event) {
this.focus = false;
this.checkVal();
this.updateModel(event);
this.updateModelValue(event.target.value);
if (this.$el.value !== this.focusText) {
let e = document.createEvent('HTMLEvents');
Expand Down Expand Up @@ -133,18 +138,18 @@ export default {
this.clearBuffer(begin, end);
this.shiftL(begin, end - 1);
this.updateModel(event);
this.updateModelValue(event.target.value);
event.preventDefault();
} else if (k === 'Enter') {
// enter
this.$el.blur();
this.updateModel(event);
this.updateModelValue(event.target.value);
} else if (k === 'Escape') {
// escape
this.$el.value = this.focusText;
this.caret(0, this.checkVal());
this.updateModel(event);
this.updateModelValue(event.target.value);
event.preventDefault();
}
Expand Down Expand Up @@ -203,7 +208,7 @@ export default {
event.preventDefault();
}
this.updateModel(event);
this.updateModelValue(event.target.value);
if (completed) {
this.$emit('complete', event);
Expand Down Expand Up @@ -420,7 +425,7 @@ export default {
var pos = this.checkVal(true);
this.caret(pos);
this.updateModel(event);
this.updateModelValue(event.target.value);
if (this.isCompleted()) {
this.$emit('complete', event);
Expand All @@ -439,16 +444,19 @@ export default {
return unmaskedBuffer.join('');
},
updateModel(e) {
let val = this.unmask ? this.getUnmaskedValue() : e.target.value;
updateModelValue(value) {
const val = this.unmask ? this.getUnmaskedValue() : value;
this.currentVal = value;
this.$emit('update:modelValue', this.defaultBuffer !== val ? val : '');
},
updateValue(updateModel = true) {
if (this.$el) {
if (this.modelValue == null) {
this.$el.value = '';
updateModel && this.$emit('update:modelValue', '');
updateModel && this.updateModelValue('');
} else {
this.$el.value = this.modelValue;
this.checkVal();
Expand All @@ -458,11 +466,7 @@ export default {
this.writeBuffer();
this.checkVal();
if (updateModel) {
let val = this.unmask ? this.getUnmaskedValue() : this.$el.value;
this.$emit('update:modelValue', this.defaultBuffer !== val ? val : '');
}
if (updateModel) this.updateModelValue(this.$el.value);
}
}, 10);
}
Expand Down

0 comments on commit 4e451e7

Please sign in to comment.