ngx-mask
ngx-mask copied to clipboard
Issue with dynamic validation changing
Hi,
I am trying to create a payment form which has dynamic masks depending on card types. I am using the following code.
<input required formControlName="cardNumber" [mask]="cardNumberMask" matInput />
It works fine while switching between single masks like
All : cardNumberMask = '0000-0000-0000-0000'
Amex : cardNumberMask = '0000-0000-0000-000'
Mastro 19 Digits : cardNumberMask = '0000-0000-0000-0000-000'
But when I use the || operator it starts messing up.
All : cardNumberMask = '0000-0000-0000-0000'
Amex : cardNumberMask = '0000-0000-0000-000'
Mastro 19 Digits || 16 Digits : cardNumberMask = '0000-0000-0000-0000||0000-0000-0000-0000-000'
Expected : Validation should be updated as per selected mask. Actual : The validation with OR condition mask persist
Stackblitz example. Steps :
- Enter 111... till the mask allows to add - Works as expected
- Click change mask. Mask changes.
- Enter 111... till the mask allows to add - Works as expected
- Click change mask. Mask changes.
- Enter 111... till the mask allows to add - Works as expected
- Click change mask. Mask changes. (Mask 1 gets selected)
- Enter 111... till the mask allows to add - Doesn't work as expected. Allows 19 digits where as mask is of 16 digits