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

Masking not working properly when used with ControlValueAccessor

Open Ron-Wieder opened this issue 4 years ago • 1 comments

🐞 bug report

Is this a regression?

Don't know

Description

I'm using a small component with single responsibility to present an input field with a FormControl value passed as directive. Since the passed value is in the shape of [FormControl], the component makes use of Angular ControlValueAccessor interface. In that component template there's use of input field with a [value] directive, which suppose to show the value on the initialization of the component, in case a value is given. That happens as it shpuld, but when attaching the mask directive to the input field of that component, then the value is not shown on the initialization lifecycle hook of the component.

Issue can be seen here: https://stackblitz.com/edit/angular-ivy-mask-w3fbyb

Work around I have found for this issue is to make use of angular's [ngModel] directive instead of [value].

Ron-Wieder avatar May 09 '21 10:05 Ron-Wieder

This issue is happening because ngx-mask itself implements a control value accessor. https://github.com/JsDaddy/ngx-mask/blob/fb6f176ce841bb78b3ec5ca4e3a3d52bce7404ac/projects/ngx-mask-lib/src/lib/mask.directive.ts#L34

Using multiple control value accessors is not supported as they are the single source of truth: https://github.com/angular/angular/issues/16755#issuecomment-321614839

zacnomore avatar May 26 '21 22:05 zacnomore

Closed because it's a duplicate #823

andriikamaldinov1 avatar Sep 25 '23 10:09 andriikamaldinov1