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

1
  • when i change var currentCulture="pt-BR"; to something then it should show en-US date picker.. but its not showing..thats the issue Commented Dec 7, 2013 at 15:39

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

3 Comments

if i put $(".datefield2").datepicker($.datepicker.regional['']); on top ..then changemonth dropdown not showing..you can check in jsfiddle too
@Spenzo your syntax doesn't match what I provided, and sugegst you intialize datepicker first
@charlietfl sorry mate ,but could you please see jsfiddle i am using..whats wrong in that..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.