2

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 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the reply I'm using the placeholder property in combination with the label and some custom CSS to style the placeholder like a regular input entry. Works quite well.
You welcome @chrisch . Yes a little bit of patching is required but glad to know it works for you. I have same course of action in my own angular/vue projects :p

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.