Reputation: 1365
I'm trying to include the jQuery UI datepicker with a default locale using
jQuery(document).ready(function($){
$.datepicker.setDefaults($.datepicker.regional["it"]);
$('#div-where-place-datepicker').datepicker({
"dateFormat": "dd/mm/yy"
});
});
According to docs I'm adding it to a div so the datepicker is shown inline on page load (like a calendar).
The problem is that after page load the calendar is not localized (english texts) and after I interact with it it loads the localization (it becomes italian).
Any fix for this?
Upvotes: 2
Views: 6310
Reputation: 220
I had the same issue. My solution was to not wrap the datepicker function within an anonymous function.
//jQuery(function($){
$.datepicker.regional['de'] = {...};
$.datepicker.setDefaults($.datepicker.regional['de']);
//});
Upvotes: 0
Reputation: 1365
I have found where is the problem and fixed it :)
I'm including the scripts (including the localization i18n) in the footer for a faster page load (after my init script) so I've moved the scripts in the header (before my init script) and now the localization is loaded on first execution.
Upvotes: 3
Reputation:
Just a guess, but try setting the defaults after you've created the datepicker instance.
The other option might be to try setting the localization of that specific instance when you create it vs setting the default then creating it. Per jquery UI docs
$( "#datepicker" ).datepicker( $.datepicker.regional[ "fr" ] );
Upvotes: 0