0

I am working on MVC4 project.My project have globalization.So i have to convert everything according to culture.

My culture will contain either pt-BR or en-US ... So i want to show jquery datepicker according to culture.

with reference from

How to set locale format from datepicker? and http://api.jqueryui.com/datepicker

i am able to show date picker in brazil but when i put condition its not working.Its not showing months as english. I have created jsfiddle also ,here is url http://jsfiddle.net/3unnf/

and code

         //if i put value pt-BR ,its showing as brazilian culure but 
    //when i change its value ,it goes to else condition but do not show 
   // default culture ie. en-US

        $(function() {
                var currentCulture="pt-BR";
               // $(".datefield2").datepicker($.datepicker.regional['pt-BR']);
               if ($("#currentCulture").val() == "pt-BR") {
                    $(".datefield2").datepicker({
                        changeMonth: true,
                        changeYear: true
                    }).attr('readonly', 'readonly');
        alert('qq1');
                    $(".datefield2").datepicker($.datepicker.regional["pt-BR"]);
                }
                else {
                    alert('qq');
                    $(".datefield2").datepicker({
                        changeMonth: true,
                        changeYear: true,
                        dateFormat: 'mm/dd/yy'
                    }).attr('readonly', 'readonly');
                    $(".datefield2").datepicker($.datepicker.regional[""]);
                }
            });

EDIT : if i put $(".datefield2").datepicker($.datepicker.regional['']); on top in else condition ..then changemonth dropdown not showing..you can check in jsfiddle too

Community
  • 1
  • 1
Mahajan344
  • 2,492
  • 6
  • 39
  • 90
  • when i change var currentCulture="pt-BR"; to something then it should show en-US date picker.. but its not showing..thats the issue – Mahajan344 Dec 07 '13 at 15:39

1 Answers1

1

You are only checking the currentCulture on page load. To change datepicker locale dynamically follow example in datepicker demos:

$("#currentCulture").change(function() {

    $(".datefield2").datepicker( "option",
    $.datepicker.regional[ $( this ).val() ] );

});

See View Source in jQueryUI demo

charlietfl
  • 170,828
  • 13
  • 121
  • 150
  • if i put $(".datefield2").datepicker($.datepicker.regional['']); on top ..then changemonth dropdown not showing..you can check in jsfiddle too – Mahajan344 Dec 07 '13 at 15:58
  • @Spenzo your syntax doesn't match what I provided, and sugegst you intialize `datepicker` first – charlietfl Dec 07 '13 at 16:00
  • @charlietfl sorry mate ,but could you please see jsfiddle i am using..whats wrong in that.. – Mahajan344 Dec 07 '13 at 16:04