Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the language of datepicker

Tags:

jquery

I am trying to build a function that changes the language of date picker

$(function(){
txtDate = $("#txtDate");
var minDate = new Date(2011, 1 - 1, 15);
var maxDate = new Date(2011, 6 - 1, 15);
txtDate.date
txtDate.dateEntry({
            defaultDate: maxDate,
            minDate: minDate,
            maxDate: maxDate,
            spinnerImage: ''
        });
txtDate.datepicker({
            minDate: minDate,
            maxDate: maxDate
        });

txtDate.datepicker("setDate", maxDate);
dateLanguageChange();
});


var dateLanguageChange = function () {
        $("#txtDate").datepicker("destroy").datepicker($.datepicker.regional["fr"]);
    };

html:

<div class="form-row">
    <label>@Html.Resource("Date")</label>
    <input id="txtDate" type="text" class="date-box" />
</div>
like image 974
dan_vitch Avatar asked Sep 30 '11 03:09

dan_vitch


1 Answers

have you tried using jQuery UI Datepicker It's a highly configurable plugin and provides support for localizing its content to cater for different languages and date formats.

$(function() {
$("#txtDate").datepicker({
dateFormat: 'dd/mm/yy',
minDate: '-10y',
maxDate: 'now',         
changeMonth: true,
changeYear: true,
firstDay: 1
});
$.datepicker.setDefaults($.datepicker.regional['fr']);
});

your html

<input id="txtDate" type="text" class="date-box" />

Note:configure datepicker options accordingly....make sure to include jquery.ui.datepicker-fr.js Hope it helps!!!

like image 61
user Avatar answered Sep 30 '22 05:09

user