ngx-mask icon indicating copy to clipboard operation
ngx-mask copied to clipboard

Enable mask validate programmatically

Open IvanBean opened this issue 5 years ago • 4 comments

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.

IvanBean avatar Nov 30 '19 13:11 IvanBean

Bump. Having the same issue. Anyone know a workaround for this?

velechva avatar May 20 '20 14:05 velechva

Any luck so far?

vishal4799 avatar Jun 15 '20 17:06 vishal4799

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.

tobigit avatar Jan 10 '22 10:01 tobigit

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+

JoaoPauloLisboa avatar Feb 16 '22 16:02 JoaoPauloLisboa

@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

andriikamaldinov1 avatar Aug 03 '23 14:08 andriikamaldinov1