Angular material Datepicker throws More than one custom value accessor matches form control with unspecified name attribute

dGayand

I have used a material datepicker widget in my angular (7) application. The html is given below.

 <mat-form-field>
<input matInput [matDatepicker]="picker" placeholder="Expiry Date" [formControl]="expiryDateInputCtrl">
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker #picker></mat-datepicker>
<mat-hint *ngIf="isExpiryDateInvalid()" [ngStyle]="{'color': 'red'}" align="start">Invalid Expiry Date</mat-hint>

However, this throws below error at runtime.

More than one custom value accessor matches form control with unspecified name attribute
at _throwError (forms.js:2144)
at forms.js:2202
at Array.forEach (<anonymous>)
at selectValueAccessor (forms.js:2191)
at new FormControlDirective (forms.js:5042)
at createClass (core.js:22160)
at createDirectiveInstance (core.js:22029)
at createViewNodes (core.js:23255)
at createEmbeddedView (core.js:23163)
at callWithDebugContext (core.js:24177)

I have used the formcontrol "expiryDateInputCtrl" to read the input value in the text field to check whether the user has entered a valid date. As far as I'm aware, there is no other way to validate the input date. Can anyone please tell the reason

dGayand

I found the issue. I have used the TrimValueAccessorModule to remove unwanted spaces from input controls and that cause this issue. Below is the working code

<mat-form-field style="width: 100%;">
<input matInput [matDatepicker]="picker" placeholder="Expiry Date" (dateChange)="onExpiryDateChange($event)" class="ng-trim-ignore" name="expiryDate" [formControl]="expiryDateInputCtrl">
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker #picker></mat-datepicker>
<mat-hint *ngIf="isExpiryDateInvalid()" [ngStyle]="{'color': 'red'}" align="start">Invalid Expiry Date</mat-hint>

here adding class="ng-trim-ignore" solved the issue

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

No value accessor for form control with unspecified name attribute Angular 2

No value accessor for form control with unspecified name attribute

ERROR Error: No value accessor for form control with unspecified name attribute on switch

Angular 7 Reactive forms "No value accessor for form control with unspecified name attribute"

form control error:ERROR Error: No value accessor for form control with unspecified name attribute

Angular form group: cannot find control with unspecified name attribute

Cannot find control with unspecified name attribute in angular 6 form builder

Angular unit Test: Error: No value accessor for form control with name: 'phoneNumber'

Angular reactive forms, input Error: No value accessor for form control with name

No value accessor for form control with name error in angular 7

Angular Cannot find control with unspecified name attribute

Angular 6: ERROR Error: Cannot find control with unspecified name attribute with angular material and reactive forms

Angular Material datepicker to set timestamp as form control value

No value accessor for form control with name: 'recipient'

No value accessor for form control with name: 'dateTime'

No value accessor for form control with name: 'recaptchaReactive'

A problem with "No value accessor for form control with name"

Angular4 - No value accessor for form control

Angular4 - No value accessor for form control

Angular4+ No value accessor for form control

No value accessor for form control

Angular 7: "Cannot find control with unspecified name attribute"

Angular 2 Cannot find control with unspecified name attribute on formArrays

FormArray : Cannot find control with unspecified name attribute in angular6

Angular 4 Error: Cannot find control with unspecified name attribute

Form tag error:No value > accessor for form control with name

Angular: trying to add recaptcha. Error => No value accessor for form control with name: 'captcha'

How to fix 'Error: No value accessor for form control with name' in Angular Unit Test?

No value accessor for form control with name... for mat-select controls