19.4.1 • Published 5 months ago

ngx-mat-date-input v19.4.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

NgxMatDateInput

An Angular Material library for entering a date.

NPM npm version npm bundle size npm

  1. Split a date into 3 input fields, day, month and year, then reassemble and save them into a given formControl.
  2. Automatically add 0 in front of the day/month number.
  3. Control the form value with the max number for day & month
  4. Remove . and e from the possible input.
  5. Does automatically focus the next field when needed.
  6. Based on the Vitaly Friedman article, Designing Birthday Picker UX: Simpler Is Better
filloutlined
Input exampleInput example

Supports:

  • Angular >=15
  • Angular Material >=15

Demo

Add NgxMatDateInputComponent to your component file:

imports: [NgxMatDateInputComponent];

Example

  • Add floatLabel to your mat-form-field
  • Use a preset formControlName
  • This formControlName will be automatically updated, therefore giving you the possibility to add your own mat-error see the comment
<form #f="ngForm" [formGroup]="dateForm">
  <mat-form-field
    floatLabel="always"
  >
    <!-- <mat-label>Date</mat-label> -->
    
    <!-- 
      <mat-datepicker-toggle matIconPrefix [for]="myDatePicker">
        <mat-icon matDatepickerToggleIcon>calendar_today</mat-icon>
      </mat-datepicker-toggle>
      <mat-datepicker touchUi #myDatePicker></mat-datepicker> 
    -->

    <ngx-mat-date-input
      formControlName="date"
      id="date"
    >
    <!-- [matDatepicker]="myDatePicker" -->
    </ngx-mat-date-input>

    <!-- <mat-icon matSuffix>event</mat-icon>
    <mat-error *ngIf="dateForm?.get('date').invalid">
      {{ Invalide error message }}
    </mat-error> -->
  </mat-form-field>
</form>

Options

OptionsTypeDefaultDescription
formControlNameFormControlundefinedControl to be updated
autocomplete"on" or "off""on"Use the default browser autofill
labelsstring[]["DD", "MM", "YYYY"]Label used by the mat-input
placeholdersstring[]["", "", ""]with an s
requiredbooleanundefined
disabledbooleanundefined
mindateundefinedActivate min validators on each fields
fields{day: boolean, month: boolean, year: boolean}{day: true, month: true, year: true}Show specifies fields

Css variable

NameDefaultExplanation
--ngx-mat-date-input-gap16pxChange the gap between the inputs

Auto formatting

Month

  • Max 12

Day

  • Month: 2 -> max 29
  • Month: 4, 6, 9 & 11 -> max 30
  • Month: else -> max 31

Authors and acknowledgment

BuyMeACoffee

19.4.1

5 months ago

19.4.0

6 months ago

19.3.0

6 months ago