1
votes

I'm using the Angular Material Datepicker. Is it possible to display a custom text in the field if the value of the input is empty or null? I didn't find a solution for this in the Datepicker API.

In my use case, the user can set an optional release date for an article. If the user don't set a specific release date (date is null), I want to display a text in the input field like "No release restriction" or "Release immediately" or something like that.

Thanks for any help.

1

1 Answers

1
votes

Assuming that you are using Material Inputs as well, you can very easily manage the labels for the date input.

<mat-form-field appearance="fill">
  <mat-label>YOUR LABEL or {{yourLabel}}</mat-label>
  <input matInput [matDatepicker]="picker">
  <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
  <mat-datepicker #picker></mat-datepicker>
</mat-form-field>

Even without the material inputs, you can manage the placeholder of input to show text when input is empty.

A step further will be to listen to datepicker changes in angular and dynamically add/append other data if you require more than just a text field