Add form support to `InputMask`

pull/6632/head
Mert Sincan 2024-10-23 13:44:56 +01:00
parent eeacc7cf89
commit 9a68b37d1d
3 changed files with 14 additions and 41 deletions

View File

@ -1,12 +1,11 @@
<script> <script>
import BaseComponent from '@primevue/core/basecomponent'; import BaseInput from '@primevue/core/baseinput';
import InputMaskStyle from 'primevue/inputmask/style'; import InputMaskStyle from 'primevue/inputmask/style';
export default { export default {
name: 'BaseInputMask', name: 'BaseInputMask',
extends: BaseComponent, extends: BaseInput,
props: { props: {
modelValue: null,
slotChar: { slotChar: {
type: String, type: String,
default: '_' default: '_'
@ -38,26 +37,6 @@ export default {
readonly: { readonly: {
type: Boolean, type: Boolean,
default: false default: false
},
invalid: {
type: Boolean,
default: false
},
disabled: {
type: Boolean,
default: false
},
name: {
type: String,
default: null
},
variant: {
type: String,
default: null
},
fluid: {
type: Boolean,
default: null
} }
}, },
style: InputMaskStyle, style: InputMaskStyle,

View File

@ -9,7 +9,7 @@
:name="name" :name="name"
:variant="variant" :variant="variant"
:placeholder="placeholder" :placeholder="placeholder"
:fluid="hasFluid" :fluid="$fluid"
:unstyled="unstyled" :unstyled="unstyled"
@input="onInput" @input="onInput"
@compositionend="onInput" @compositionend="onInput"
@ -24,7 +24,6 @@
<script> <script>
import { getUserAgent } from '@primeuix/utils/dom'; import { getUserAgent } from '@primeuix/utils/dom';
import { isEmpty } from '@primeuix/utils/object';
import InputText from 'primevue/inputtext'; import InputText from 'primevue/inputtext';
import { mergeProps } from 'vue'; import { mergeProps } from 'vue';
import BaseInputMask from './BaseInputMask.vue'; import BaseInputMask from './BaseInputMask.vue';
@ -33,7 +32,7 @@ export default {
name: 'InputMask', name: 'InputMask',
extends: BaseInputMask, extends: BaseInputMask,
inheritAttrs: false, inheritAttrs: false,
emits: ['update:modelValue', 'focus', 'blur', 'keydown', 'complete', 'keypress', 'paste'], emits: ['focus', 'blur', 'keydown', 'complete', 'keypress', 'paste'],
inject: { inject: {
$pcFluid: { default: null } $pcFluid: { default: null }
}, },
@ -54,7 +53,7 @@ export default {
}, },
updated() { updated() {
if (this.isValueUpdated()) { if (this.isValueUpdated()) {
this.updateValue(); this.updateValueByModel();
} }
}, },
methods: { methods: {
@ -111,6 +110,7 @@ export default {
} }
this.$emit('blur', event); this.$emit('blur', event);
this.formField.onBlur?.(event);
}, },
onKeyDown(event) { onKeyDown(event) {
if (this.readonly) { if (this.readonly) {
@ -450,15 +450,15 @@ export default {
this.currentVal = value; this.currentVal = value;
this.$emit('update:modelValue', this.defaultBuffer !== val ? val : ''); this.updateValue(this.defaultBuffer !== val ? val : '');
}, },
updateValue(updateModel = true) { updateValueByModel(updateModel = true) {
if (this.$el) { if (this.$el) {
if (this.modelValue == null) { if (this.d_value == null) {
this.$el.value = ''; this.$el.value = '';
updateModel && this.updateModelValue(''); updateModel && this.updateModelValue('');
} else { } else {
this.$el.value = this.modelValue; this.$el.value = this.d_value;
this.checkVal(); this.checkVal();
setTimeout(() => { setTimeout(() => {
@ -524,16 +524,13 @@ export default {
} }
this.defaultBuffer = this.buffer.join(''); this.defaultBuffer = this.buffer.join('');
this.updateValue(false); this.updateValueByModel(false);
}, },
isValueUpdated() { isValueUpdated() {
return this.unmask ? this.modelValue != this.getUnmaskedValue() : this.defaultBuffer !== this.$el.value && this.$el.value !== this.modelValue; return this.unmask ? this.d_value != this.getUnmaskedValue() : this.defaultBuffer !== this.$el.value && this.$el.value !== this.d_value;
} }
}, },
computed: { computed: {
filled() {
return this.modelValue != null && this.modelValue.toString().length > 0;
},
inputClass() { inputClass() {
return [this.cx('root'), this.class]; return [this.cx('root'), this.class];
}, },
@ -545,12 +542,9 @@ export default {
ptmParams() { ptmParams() {
return { return {
context: { context: {
filled: this.filled filled: this.$filled
} }
}; };
},
hasFluid() {
return isEmpty(this.fluid) ? !!this.$pcFluid : this.fluid;
} }
}, },
components: { components: {

View File

@ -4,7 +4,7 @@ const classes = {
root: ({ instance }) => [ root: ({ instance }) => [
'p-inputmask', 'p-inputmask',
{ {
'p-filled': instance.filled 'p-filled': instance.$filled
} }
] ]
}; };