ngx-mask
ngx-mask copied to clipboard
Enable mask validate programmatically
Hi,
I have a FormControl which enable/disable required validator programmatically by formControl.setValidators([Validators.required]), due to setValidators will remove every validator previously include mask validator, can I re-enable mask validator by setValidators?
formControl.setValidators([Validators.required, /* how to call mask validator here */])
Thanks.
Bump. Having the same issue. Anyone know a workaround for this?
Any luck so far?
You have to use addValidators() to keep the mask validator function, because setValidators() removes all other validators. To remove a specific validator you can use removeValidators() and pass the validatorFn you want to remove.
You have to use addValidators() to keep the mask validator function, because setValidators() removes all other validators. To remove a specific validator you can use removeValidators() and pass the validatorFn you want to remove.
addValidators and removeValidators only works on Angular 12+
@velechva @IvanBean @vishal4799 Thanks for your using Ngx-Mask. Please update to latest version. Maybe the problem was in earlier versions, but now everything works as expected - https://stackblitz.com/edit/angular-4tckz6?file=src%2Fmain.ts