like the topic says: in my project i have a md-datepicker, which in some cases (which are intended) shows "Invalid Date". Is there any possibility to translate or change this text?
Asked
Active
Viewed 2,294 times
1 Answers
4
Yes.
Actually, I'd got the same problem and "Invalid Date" should not be good at all. I thought it should be blank.
In my project, it happened when I enabled "md-open-on-focus" and I click on the input (not on icon or caret).
In addition, I was using Moment.js with the following configuration:
$mdDateLocaleProvider.formatDate = function (date)
{
return moment(date).format('DD/MM/YYYY');
};
As you can see, an invalid date like null or empty was formated and then returned.
Then, I've solved it by replacing it to this:
$mdDateLocaleProvider.formatDate = function (date)
{
var tempDate = moment(date);
return (tempDate.isValid() ? tempDate.format('DD/MM/YYYY') : '');
};

Marcelo Santos
- 128
- 1
- 4
-
1That worked. I did the exact same thing with Moment.js.Thank you very much! – Philipp Kohlmann May 19 '17 at 11:50
-
This only works in AngularJS and not Angular Material running on v6+ – joe.feser Oct 02 '18 at 23:10