-
Notifications
You must be signed in to change notification settings - Fork 215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow undefined to be passed to v-mask directive #82
Comments
I have the very same issue. |
I'm also facing this issue. |
Same issue. PR #34 should resolve this issue. |
Same issue! Very cool and simple directive, but usage inside own components becomes tricky, sometimes a lot of code on input field should be duplicated because we can`t just use something like
Maybe the simpliest way to resolve this is to add a token
then we can use it like
|
Same issue. |
same |
Same |
The developer needs to implement this or implement a wild card mask. The solution I found is: import {mask} from 'vue-the-mask';
export default {
directives: {
mask: {
...mask,
tokens: {
...mask.tokens,
'*': /./,
}
},
},
...
} And in directive |
Nice! |
@samuelcust, sorry for post wrong solution. I thought the developer implemented the directive using directive properties. Like in this doc: https://br.vuejs.org/v2/guide/custom-directive.html. Reading the code. I think the hole is more deep than I thought. Really, there's no way to extend that directive to achieve that. I did add new tokens to the default ones but the problem is the length of the mask, that is hard to change. |
|
Im using v-mask plugin This solved my problem: And then I added a method like this:
The character "X" means "any symbol", which I think is the same as having no mask This way the mask will be always the same length as the input value and accept any symbol. This is the way I've found to work like it doesn't have a mask Anyway, this is a workaround and would be nice if the plugin accepted false to have no mask Please test before using |
The directive has a property masked, example: v-mask="field.mask" :masked="field.mask ? true : false" |
same here |
:masked true / false is how you want the input returned, either in it's Masked or Raw (unmasked) format. In both cases, the mask is still applied to the input field. |
I'm using this:
but I don't know if is the best way. |
Awesome solution, @MayaraRMA 👏👏👏 |
Can you show more of the code? |
@igoohd I made like this:
So if |
Your "Helpers" is only with tag script? |
It is a plain .js file, to add simple functions, and not a .vue file. |
This worked perfect for me with Vue3! Thank you @MayaraRMA for such an elegant solution even 2 years later! Edit, adding solution here as well: directives: {
mask: (el, binding) => {
if (!binding.value) return;
mask(el, binding);
}
}, |
I think the right and the safest way is to do it programmatically, in my case i use Maska almost same as what you guys use so in my custom input in a setup script :
|
The solutions here don't allow for the dynamic masks. |
My solution for this is: v-mask="option.mask ? option.mask : 'X'.repeat(255)" Tokens Edit: Doesn't allow special characters like space :v |
I widely use form builder in my app. It receives a config like [{key: name, type: string}, {key: birth, type: date},...] and builds a form. I want to add mask property to text input that related to vue-the-mask directive to be able to specify it in the config like that: {key: ssn, mask: {mask: '###-##-##', tokens: {...}}}.
The issue is that it's optional property, it's defined for ssn but it's not defined for user name field.
Currently I have to add it like that:
That's because v-mask="undefined" throws an error. I would suggest to allow undefined or null option to be passed as v-mask directive argument, and if it's passed just do not apply v-mask directive at all.
The text was updated successfully, but these errors were encountered: