Error When Used in FormArray, datepicker angular material and ngx-mask
ERROR Error: More than one custom value accessor matches form control with path: ' -> -> '
`<div [formGroup]="form">
<div formArrayName="faseConstrucao" *ngFor="let faseConstrucao of getFaseConstrucaoControl.controls; let i = index">
<div [formGroupName]="i">
@silvergama could you provide a full example ?
Ex: https://stackblitz.com/edit/angular-kmcusk
In app.component.html Add formControlName="date" in input to show error: More than one custom value accessor matches form control with unspecified name attribute
With FormArray: https://stackblitz.com/edit/angular-7qi6qo
@silvergama Unfortunately we cannot do this , check this #50
Is this bug still unfix-able ?
@aemonge please check this #50
Hi @ValeriaKochegarova , thanks for the link. But I already posted there another question related to this.
Basically over-there, the official solution is not to use ngMask.... so that's why I use this ticket to ask if there's a plan to fix the bug or should we follow the #50 guidelines and avoid the library at all.
Did anything change? Any implementation? Any workaround?
@LuanMaik it's an open source project from my reading and the maintainers have chosen to not fix it or say that it's impossible to fix. Current suggestion is to use a custom directive with a native adapter as seen in #50 .
Based on an existing solution:
https://stackoverflow.com/questions/60818529/angular-input-with-ngx-mask-matdatepicker-and-reactive-form
Hi I have a working solution:
The matDatePicker input is hidden and linked to the masked input to the hidden datepicker which binds to the formControl and bind matInput the the masked input field.
ngModelOptions is important, as there is an error thrown when using ngModel used within a form
ngModel cannot be used to register form controls with a parent formGroup directive.
HTML:
<input #dateInput type="hidden" id="date" formControlName="date" required [matDatepicker]="datePicker" [min]="today" />
<input #maskedInput matInput (input)="dispatch(dateInput)" placeholder="Pick a date"
[(ngModel)]="dateInput.value" [ngModelOptions]="{ standalone: true }" mask="00/00/0000" [dropSpecialCharacters]="false" />
<mat-datepicker-toggle matSuffix [for]="datePicker"></mat-datepicker-toggle>
<mat-datepicker #datePicker></mat-datepicker>
Component:
dispatch(input: HTMLInputElement) {
input.dispatchEvent(new Event('input'));
}