beholdr / maska

Simple zero-dependency input mask for Vue, Svelte, Alpine.js and vanilla JS.
https://beholdr.github.io/maska/
MIT License
1.79k stars 71 forks source link

Dynamic parameters not working with VueJS #242

Closed entipe closed 1 month ago

entipe commented 1 month ago

Describe the bug

With Vue, dynamic mask will be ignored.

<input type="tel" v-maska="['+32 # ### ## ##, '+32 ### ## ## ##']" />

I started with your live-demo implementation:

<details>
  <summary>Dynamic mask: CPF/CNPJ</summary>
  <input class="maska" data-maska="['###.###.###-##', '##.###.###/####-##']">
</details>

Steps to reproduce

Vue3 + Vite,

Use a Array for the v-maska attribute.

Reproduction link

Reproduction link : https://stackblitz.com/edit/vitejs-vite-yx35ze?file=src%2Fcomponents%2FHelloWorld.vue

rozsazoltan commented 1 month ago

Indeed. The v-maska does not handle array values, only strings or objects. If I pass the settings as an object, including pairing your array with the mask key, then it works.

<input type="tel" v-maska="{
  mask: ['+32 ### ## ## ##', '+32 # ### ## ##'],
}" />

So the issue is that it only doesn't handle the masks passed in the array.

<input v-maska:argument.modifier="value">
  • value could be one of:
    • string for the mask value (should be enclosed in additional quotation marks: "'#-#'")
    • object with a default options

Source: Usage with Vue - Maska Docs (Vue 3)

beholdr commented 1 month ago

Actually, you can use an array in the data-maska for dynamic masks:

<input
  type="tel"
  v-maska
  data-maska="['+32 ### ## ## ##', '+32 # ### ## ##']"
/>

Example: https://stackblitz.com/edit/vitejs-vite-c3bzdy?file=src%2Fcomponents%2FHelloWorld.vue

entipe commented 1 month ago

Many thanks !