2
I’m using the v-Mask directive, but the component data is dynamic, so at certain times I use the component with mask and at other times without mask, but in the v-Mask directive, if I use it empty only, v-Mask="" returns error, I need to use the component’s html when I have mask apply v-Mask and when I have not disabled v-Mask
<v-text-field
:rules="rules"
:name="schema.model"
:id="schema.model"
v-bind="schema.attributesTextField"
v-model="value"
:ref="schema.model"
@blur="onBlur"
@click:clear="clear()"
@change="onChange"
@focus="onFocus"
@input="onInput"
v-mask="getMask"
>
<template v-slot:label>
{{schema.attributesTextField.label}}
<span
v-if="schema.rules.includes('required')"
class="red--text"
>*</span>
</template>
</v-text-field>
import { mask } from 'vue-the-mask';
directives: {
mask
}
getMask() {
return this.schema.attributesTextField.mask || 'XX';
}
How are these dynamic data, where they are?
– LeAndrade
the settings to use this component are dynamic, today I use the schema-based form using Vue-form-Generator, and use this component for all types of input, such as type text, tel, number. the idea is to add this v-Mask directive to the component only when a service parameter comes.
– Rafael Vidal
Tried to put
return this.schema.attributesTextField.mask || false;
instead ofreturn this.schema.attributesTextField.mask || 'XX';
?– LeAndrade
Yes I tried yes, it doesn’t work
– Rafael Vidal
So, I asked about how the data are coming, pq da to make two v-text-field elements one with Mask and the other without, and then do a v-if as the data shows one element or the other.
– LeAndrade
I get it, test this way, but I wanted to know if there is another way, not to keep repeating html because of a directive
– Rafael Vidal