-
Notifications
You must be signed in to change notification settings - Fork 214
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
Clear the field automatically if it is not completely filled #51
Comments
Hey there,
<template>
<input-el
:value="value"
@input="$emit('input', $event)"
@blur="clearIncompletedField()"
@paste.prevent
v-mask="mask"
v-bind="$attrs"
/>
</template>
<script>
import { mask } from 'vue-the-mask';
export default {
inheritAttrs: false,
directives: { mask },
props: {
value: String,
mask: String,
},
methods: {
clearIncompletedField() {
if (this.value.length < this.mask.length) {
this.$emit('input', '');
}
},
},
};
</script>
|
updated example: <template>
<input-el
v-mask="mask"
:value="value"
v-bind="$attrs"
@input="$emit('input', $event)"
@blur="clearIncompletedField()"
@paste.prevent
/>
</template>
<script>
import { mask } from 'vue-the-mask';
export default {
directives: { mask },
inheritAttrs: false,
props: {
value: {
type: String,
required: true,
},
mask: {
type: [String, Array],
required: true,
},
},
methods: {
clearIncompletedField() {
if (this.mask) {
if (Array.isArray(this.mask)) {
const valueMatchesMask = this.mask.some(m => this.value.length === m.length);
if (valueMatchesMask) {
return;
}
this.$emit('input', '');
} else if (this.value.length < this.mask.length) {
this.$emit('input', '');
}
}
},
},
};
</script>
|
Thank you for the example, i had to adjust the |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good evening.
Is there any way to automatically clear the field when the mask is not completely filled?
In the jQuery Mask Plugin of Igor Escobar (https://github.com/igorescobar/jQuery-Mask-Plugin) there is the "clearIfNotMatch" option that does just that.
I need this option to "force" the user to fill in the data correctly because the field is accepting incomplete data.
The text was updated successfully, but these errors were encountered: