angular-ui / ui-mask

Mask on an input field so the user can only type pre-determined pattern
https://htmlpreview.github.io/?https://github.com/angular-ui/ui-mask/master/demo/index.html
MIT License
391 stars 258 forks source link

Skip the pr-defined characters in the mask on model binding. #204

Open pavelshtanko opened 7 years ago

pavelshtanko commented 7 years ago

For instance I have the input with the mask: 1 (999) 999 99 99 When the model for the imput is 12345678900 I've got the viewValue as 1 (123) 456 78 90.

The first pre-defined letter has been added + the phone number has been cutted (last 0).

Any propositions?

sphanley commented 7 years ago

The default Mask definitions are { '9': /\d/, 'A': /[a-zA-Z]/, '*': /[a-zA-Z0-9]/ }. This means that if you use anything other than "9", "A", or "*" in your mask definition, such as the "1" in your example, it's going to be considered a hard-coded literal character rather than part of the user-entered value, causing the behavior you're seeing. You can work around this by providing your own mask definition allowing for "1" as a mask symbol accepting only the numeral 1 - this'll cause the "1" to be considered part of the input's value just like the other digits.

pavelshtanko commented 7 years ago

That's strange solution. I may have multiple sets of mask definitions - sometimes 1 shoud act like a placeholder and sometimes not. Different countries have different codes.

And btw it leads to the next issue with the directive. When I'm trying to override the the default mask definitions the old definitions are still in game.