I’m using Vuetify 3 and Maska, which provides masking of input values. I need to put a mask for phone numbers on v-text-field
.
The documentation describes how it works with a regular HTML input element, but I need to put the mask on the Vuetify v-text-field
component. How to do it?
I tried:
<v-text-field
label="Телефон"
variant="solo"
class="mt-3"
clearable
v-maska data-maska="+7(###)-###-##-##"
v-model="form.phone"
:error-messages="v$.form.phone.$errors.map(e => e.$message)"
></v-text-field>
but it is not working. I have registered the directive with:
directives: { maska: vMaska }
2
Answers
I don’t see an option in the documentation, where you can change the event and value processed by the Maska directive, and as you said, it does not seem to work with regular
modelValue
/@update:modelValue
.But you can use Maska programmatically and mask the input and unmask the output to
v-text-field
.Just create a mask instance with
and in your
v-text-field
, replacev-model
with updated in- and output:(Again, make sure to remove
v-model
)It works in the snippet:
I had the same issue and solved it like this:
Hope it helps!