Hi Allan,
I am using moment.js to format dates. I have included the MomentJS-2.13.0 Javascript. In addition I am using two locales:
<!-- Locales for moment.js-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/locale/de.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/locale/en-gb.js"></script>
To initialize moment.js I do this:
//Moment.js (date time) location settings
if (lang === 'de') {
moment.locale('de');
} else {
moment.locale('en-gb');
}
// Return today's date and time
var currentTime = new Date();
The Data Table uses this - and it works perfectly fine. For German (lang === 'de') it returns 'DD.MM.YYY' else it returns the English Version of 'DD/MM/YYY'.
{ data: "rfp.start_date",
render: function ( data, type, row ) {
return moment(new Date(data)).format('L');
}
},
My problem is with Editor. The only thing that works here is the default unfortunately which correctly returns the current date in the German or English format.
fields: [ {
label: "Start Date:",
name: "rfp.start_date",
type: "datetime",
def: function () { return moment(currentTime).format('L');},
format: 'MM.DD.YYYY',
opts: {
showWeekNumber: true,
momentLocale: 'de'
}
}, {
label: "End Date:",
name: "rfp.end_date",
type: "datetime",
def: function () { return moment(currentTime).format('L');}
} ]
"Start Date" in this fashion only works for German because Editor forced me to hard code the format to be 'MM.DD.YYYY'. Editor does not accept the format 'L' which is a moment.js standard format used with localization. You can also see it in the respective moment locale scripts mentioned above. I tried to use a global variable predefined with one of the two formats but that produced an error. So how can I localize this? How can I preset the format so that is used correctly by Editor since it does not acceopt 'L'?
And there is another issue: Editor ignores "momentLocale: 'de'". "showWeekNumber" works however. For that reason my date picker is only in English and not shown in German.
Let's assume I get "momentLocale" working: How do I dynamically set the locale to either German or English?
"End Date" is even worse: Only the default works fine in German or English. Once you start editing the date it shows it in 'YYY-MM-DD'. For the German language setting it starts with the default of '03.02.2017'. Then I open the date picker which is in English only and if I select February 4th the date picker returns '2017-02-04' which is a problem ...
Please help!