maska
maska copied to clipboard
Error programmatically with Array
Hi,
I am trying to use programmatically mask with array, but the mask always returns a string.
{{ masky(item.phone, ['(##) #####-####', '(##) #####-####']) }}
returns:
[(##) #####-####(##) #####-####]
masky = function:
import { mask } from 'maska'
export default (value: any, masked: any) => {
if (value) {
return mask(value, masked)
}
}
tks.
same here
any solution or beter package?
Same problem here using the code bellow to watch for 'forced changes' to the input using @click on a text.
watch: {
'form.primary_phone'(val) {
if (val)
this.form.primary_phone = mask(val, ['+### (###) ###-###', '+## (###) ###-####', '+# (###) ###-####', '+## (##) ####-####', '+## (##) #####-####'])
}
}
same here, any solutions?
To what I was trying to accomplish on my previous comment:
Same problem here using the code bellow to watch for 'forced changes' to the input using @click on a text.
watch: { 'form.primary_phone'(val) { if (val) this.form.primary_phone = mask(val, ['+### (###) ###-###', '+## (###) ###-####', '+# (###) ###-####', '+## (##) ####-####', '+## (##) #####-####']) } }
https://github.com/beholdr/maska/issues/72#issuecomment-1221617112
I've made it kinda work using the maska pattern as a data variable and changing its value. I've set a v-mask on the input using a variable:
<input type="text" v-model="form.whatsapp" v-maska="whatsappMaska" placeholder="Enter your number or WhatsApp URL" />
then..
data() {
return {
whatsappMaska: ""
};
},
and in watch, I make the correct setting of the mask
"form.whatsapp"(val) {
if (val) {
if (/^[0-9]+$/.test(val) === false) this.whatsappMaska = null;
else
this.whatsappMaska = [
"+## (##) ####-####",
"+## (##) #####-####",
];
} else {
this.whatsappMaska = {
mask: "U*",
tokens: {
U: {
pattern: /.*/,
// /(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})/gi,
},
},
};
}
},
Hope that my approach can help you guys somehow. 👍
Should be fixed in v2.0