2

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?

Riccardo
  • 1,309
  • 1
  • 25
  • 35

3 Answers3

3

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.

Riccardo
  • 1,309
  • 1
  • 25
  • 35
  • Actually, I had a very similar problem: I was loading the language specific javascript file after setting my calendar to use it. I could keep it in the footer, though ;) Thanks ! – mika Mar 09 '15 at 15:36
0

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" ] );
  • 1
    Same behavior with "$.datepicker.setDefaults($.datepicker.regional["it"]);" before, after and before+after .datepicker() init. – Riccardo Mar 06 '13 at 18:03
0

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']);
//});
cephei_vv
  • 220
  • 3
  • 14