rsaenen / ngx-custom-validators

Angular custom directives for validation
129 stars 53 forks source link

min and max are colliding with Mat date component validations #19

Open mhmo91 opened 5 years ago

mhmo91 commented 5 years ago

When this module is imported in a project that is used with Mat components, a problem happens with the material date component as it uses min and max validations

    <mat-form-field class="col">
      <input matInput [matDatepicker]="from" name="fromDate" [placeholder]="fromLabel" #fromDate="ngModel" [(ngModel)]="dateFrom"
        (dateChange)="dateFromChanged()" [required]="required" [min]="minDateFrom" [max]="maxDateFrom" [disabled]="readonly"
        (click)="from.open()" autocomplete="off">
      <mat-datepicker-toggle matSuffix [for]="from"></mat-datepicker-toggle>
      <mat-datepicker #from></mat-datepicker>
      <form-validation [name]="fromDate"></form-validation>
    </mat-form-field>

when you use moment as date picker provider in the component

  providers: [
    { provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE] },
    { provide: MAT_DATE_FORMATS, useValue: MAT_MOMENT_DATE_FORMATS },
  ],

Environment information