maska icon indicating copy to clipboard operation
maska copied to clipboard

Error programmatically with Array

Open maicolbruski opened this issue 2 years ago • 4 comments

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.

maicolbruski avatar Apr 22 '22 21:04 maicolbruski

same here

mateusgalasso avatar May 20 '22 15:05 mateusgalasso

any solution or beter package?

leandrodiogenes avatar Jul 30 '22 07:07 leandrodiogenes

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, ['+### (###) ###-###', '+## (###) ###-####', '+# (###) ###-####', '+## (##) ####-####', '+## (##) #####-####'])
  }
}

lucascnunes avatar Aug 21 '22 20:08 lucascnunes

same here, any solutions?

escobarAndre avatar Sep 26 '22 13:09 escobarAndre

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. 👍

lucascnunes avatar Oct 16 '22 05:10 lucascnunes

Should be fixed in v2.0

beholdr avatar Dec 04 '22 15:12 beholdr