C. Banzet
C. Banzet

Reputation: 419

Angular Material matDatepicker doesn't work with ngForm ngSubmit when input is disabled

I have a problem with Angular Material matDatepicker.

I have found that if I want to use the disabled attribute on it, I can't get the result value when using ngSubmit.

Means this code works :

    <mat-form-field>
      <input matInput [matDatepicker]="picker" required
        ngModel #datePress="ngModel" 
        name="datePress">
      <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
      <mat-datepicker #picker></mat-datepicker>
    </mat-form-field>

But this one doesn't work :

    <mat-form-field class="full-width">
      <input matInput [matDatepicker]="datepicker2" required disabled
        ngModel #newTourEndDate="ngModel"
            name="newTourEndDate">
      <mat-datepicker-toggle matSuffix [for]="datepicker2"></mat-datepicker-toggle>
      <mat-datepicker #datepicker2 disabled="false"></mat-datepicker>
    </mat-form-field>

Is there any chance to use the disabled attribute with matDatePicker and ngForm ?

Upvotes: 0

Views: 507

Answers (1)

Guntram
Guntram

Reputation: 980

To get disabled inputs values, you need to use something like:

this.formGroup.getRawValue();
this.form.getRawValue();
this.form.form.getRawValue();

Upvotes: 0

Related Questions