jQuery UI datepicker: How to change the month names in the drop-down from short to long names?

Keith L. picture Keith L. · Apr 24, 2012 · Viewed 35.9k times · Source

I need to change the month names from short names to long names in my jQuery UI datepicker.

My properties are:

$.datepicker.regional['de'] = {
    prevText: '<zurück',
    nextText: 'vor>',
    monthNames: ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni',
            'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'],
    monthNamesShort: ['Jan', 'Feb', 'Mär', 'Apr', 'Mai', 'Jun',
            'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez'],
    dayNames: ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'],
    dayNamesShort: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
    dayNamesMin: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
    weekHeader: 'Wo',
    dateFormat: 'dd.mm.yy',
    firstDay: 1,
    changeMonth: true,
    changeYear: true,
    yearRange: "-0:+2",
    isRTL: false,
    showMonthAfterYear: false,
    minDate: 0
 };

$.datepicker.setDefaults($.datepicker.regional['de']);
var dates = $("#von, #bis").datepicker({
    showOn: "button",
    buttonImage: "calendar.png",
    buttonImageOnly: true,
    buttonText: 'Datum w\u00E4hlen',
    onSelect: function (selectedDate) {
        var option = this.id == "#von" ? "minDate" : "maxDate",
                instance = $(this).data("datepicker"),
                date = $.datepicker.parseDate(
                    instance.settings.dateFormat ||
                    $.datepicker._defaults.dateFormat,
                    selectedDate, instance.settings);
        dates.not(this).datepicker("option", option, date);
    }
});

At the moment the calendar only shows short month names like "Apr" instead of "April" in the dropdown list.

Maybe I am overwriting the default long names with some piece of code?

Please help.

Answer

Bruno Arce Prado picture Bruno Arce Prado · Jun 12, 2013

Use the property monthNamesShort and attribute it the names you want.

In my case, I wanted to show, in the month drop-down, the month long name, in portuguese:

monthNamesShort: [ "Janeiro", "Fevereiro", "Março", "Abril",
                   "Maio", "Junho", "Julho", "Agosto", "Setembro",
                   "Outubro", "Novembro", "Dezembro" ]