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

白昼怎懂夜的黑 提交于 2019-12-04 17:05:17

问题


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.


回答1:


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" ]



回答2:


It's not possible at the moment. See https://github.com/jquery/jquery-ui/pull/590 for details.




回答3:


In many places they use the dateFormat to determine which list to use. Unfortunately in this block of code they weren't consistent using it. I made an adjustment to follow their method in _generateMonthYearHeader (around line 8985):

replace

  monthNamesShort[ month ]

with

 (inst.settings.dateFormat.match(/MM/) ? monthNames : monthNamesShort)[ month ]


来源:https://stackoverflow.com/questions/10294232/jquery-ui-datepicker-how-to-change-the-month-names-in-the-drop-down-from-short

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!