Philipp Kohlmann
Philipp Kohlmann

Reputation: 33

How to translate the md-datepickers "Invalid Date" message?

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?

Upvotes: 3

Views: 2326

Answers (1)

Marcelo Santos
Marcelo Santos

Reputation: 128

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') : '');
    };

Upvotes: 4

Related Questions