RobinHerbots / Inputmask

Input Mask plugin
https://robinherbots.github.io/Inputmask/
MIT License
6.36k stars 2.18k forks source link

VueJS v-model unmasked value #2769

Closed Aroxed closed 5 months ago

Aroxed commented 5 months ago

Hi. I have an input definition in a Vue component template:

                  <div v-for="i in 4" :key="i">
                    <input type="text" class="tel" v-model="myArray['phone'+i]"/>
                  </div>

and its initialization in mounted(): Inputmask({"mask": "+38 (999) 999 99 99", "autoUnmask": true}).mask('.tel');

The issue is when I retrieve a phone number in myArray, it has a value length equal to 10 (like '1234567890') but I want to get 13-length (like '+381234567890').

Is it possible?

Thanks in advance.

Techn1c4l commented 5 months ago

If you use autoUnmask option it's going to strip anything but the number wildcard (9 in this case). I think you can manually add '+38' to your unmasked value using the onUnMask event handler:

Inputmask({
  "mask": "+38 (999) 999 99 99",
  "autoUnmask": true,
  "onUnMask": (maskedValue, unmaskedValue) => '+38' + unmaskedValue;
}).mask('.tel');