Updating date picker causes loss of format
I am currently using the date picker with the en-GB locale and its working perfectly until I have to call either update or setDate. The date sets fine however the date picker suddenly reverts from dd/mm/yyyy format to mm/dd/yyyy format. It's as if calling either method is reverting the date picker back to default settings.
If you require further information please let me know. I'm using v1.5.1.
Same for me: not only it reverts to default format, but it changes locale to default too.
Is this ever going to be fixed or should we wait for v2?
Hi here, can you guys provide some snippets or jsfiddle of your implementation ?
I cannot reproduce your issue either in 1.5.1, 1.6.4 or 1.7.0.
Hi there, I came across this post as I was having similar issues. I realised I had version 1.5.0. I updated and still the issue remains. I am simply calling closedDateDP.datepicker('update', d); I have also tried closedDateDP.datepicker('update', d.toLocaleDateString('en-GB')); and closedDateDP.val(d.toLocaleDateString('en-GB')); The latter of which looks correct, but then results in a null date in the controller. If I select from the calendar, the controller has a value.
Also, having called closedDateDP.datepicker('update',....... I get an additional calendar when I click the calendar icon in the UI! Please can you assist me.
For further info (in case anyone else finds this thread!) This seems to work for me closedDateDP.datepicker({'update': d.toLocaleDateString('en-GB')}, {culture: 'en-GB'} );
I just set the culture again on update.
Ironically, the above has now stopped working - It worked I swear, but when I added an update to null the whole lot dies and even removing that the first statement no longer works! Please help me to set the datepicker
Hi, Once again I need a full sample of what you are doing because as far as I can tell everything is working as expected for me. I'm thinking that there is some misunderstanding about formats here but I can't tell 100% without more details.
I ran those snippets without noticeable issues:
$('#datepicker0').datepicker();
$('#button0').on('click', function () {
$('#datepicker0').datepicker('update', new Date(2016, 10, 18));
});
// datepicker0 shows 11/18/2016 as expected
$('#datepicker1').datepicker({
language: 'en-GB'
});
$('#button1').on('click', function () {
$('#datepicker1').datepicker('update', new Date(2016, 10, 18));
});
// datepicker1 shows 18/11/2016 as expected
$('#datepicker2').datepicker({
language: 'en-GB',
format: 'yyyy-m-d'
});
$('#button2').on('click', function () {
$('#datepicker2').datepicker('update', new Date(2016, 10, 18));
});
// datepicker2 shows 2016-11-18 as expected
Please note that all methods are dependent of the format option.
Which means that if you set format to yyyy-m-d, then sending 18/11/2016 or 11/18/2016 (or d.toLocaleDateString('en-GB')) won't works, it will need to be 2016-11-18.
It worked for me by setting the global default format ($.fn.datepicker.defaults.format = 'yyyy-mm-dd';) instead of on initialization ($('#pick-a-date').datepicker({format: 'yyyy-mm-dd'});)
Hi @Azaret, please look at this jsfiddle. After clicking update button, datepicker is reset to default language and format.
I'm having the same issue. I initialise using the following, and it works fine
$.fn.datepicker.defaults.format = 'dd/mm/yyyy'; /* Added after readingthis thread in the hope it will help) */
$('#ValidToDate').datepicker({
format: "dd/mm/yyyy",
maxViewMode: 2,
todayBtn: true,
defaultViewDate: { year: Date.now.year, month: Date.now.month, day: Date.now.day }
});
Then I call an update
$("#ValidToDate").datepicker('update', '14/05/2019');
After which the datepicker displays 02/05/2019 and acts as though the date is a mm/dd/yyyy format - so when I open the datepicker, it sees the date as the 5th of Feb.
Interestingly, the 14th (dd) becomes February (mm) - so it looks like the 14 is overflowing as 14%12=2?
I'm still having the same issue. Did anybody figured it out?
I managed to fix it with this answer