Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: emit unmask value to update:modelValue when unmask mode #6407

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading