springrolls
springrolls

Reputation: 1331

JQuery DatePicker ignores DateFormat

I have a datepicker component in my C# app, which takes its default value from the server through AJAX call. The problem is, it ignores the date format I've defined as a parameter. I looked into the code and it seems that the date format is not set on the settings variable, so JQuery uses the default value (mm/dd/yy).

Here is my code:

$.when(_getUserProfileValue(defValue))
    .done(function (result) {
        // result is 23.07.2015
        // this line shows the correct date and format
        $("#divTest").text(result.d);
       // new Date(res) gives back invalid date, but datepicker shows the result from server
       // without this line, datepicker shows a completely wrong date
       // TODO: format is still ignored
       var aDate = new Date(result.d);
       $calendar.datepicker({
           dateFormat: "dd.mm.yy"
       });
       $calendar.datepicker("setDate", aDate);
   })

Any ideas?

Upvotes: 2

Views: 1217

Answers (1)

Arun P Johny
Arun P Johny

Reputation: 388316

Might be because you have already initialized the datepicker on that element, in that case to update the date format of an existing datepicker use the option method like

$calendar.datepicker('option', 'dateFormat', "dd.mm.yy");

Upvotes: 2

Related Questions