Buy Now
Sign in

wrong format when initialising Calendar

E
emmexx
if($(calfield).val().length > 0){
$realDate.val(moment($(calfield).val(), dformat).format(sformat));
}


The following code of cegcore2 js takes the initial value of a calendar field and puts the formatted value in its ghost input value.
Probably the code works when dformat and sformat are the same or similar (yyyy-mm-dd and yyyy/mm/dd).
But when they're not similar, as is the case with italian dates, that code sets a value of "Invalid Date".

Similar problem with the following code:

parser:{
date: function (text, settings) {
if (!text) return '';
return moment(text, dformat).toDate();
}
,


text is formatted as YYYY-MM-DD and moment parses it as DD-MM-YYYY.
So the calendar input field is empty, the ghost value is Invalid Date.

This happens when you load a form with values from a db record or when you use a calendar to filter a table by date (using session values).

maxx