BadHorsie
BadHorsie

Reputation: 14544

jQuery Datepicker - Show full month names in select box

It's really bugging me that the jQuery datepicker has a select box for changing the month but it doesn't show the full month name (but it does in the other months).

Screenshot: https://i.sstatic.net/N1gTU.png

Is there a way to customise the datepicker to show the full month name without modifying the source code?

Upvotes: 7

Views: 28726

Answers (6)

Helena Silkina
Helena Silkina

Reputation: 1

You can define attribute "monthNamesShort" as:

 $(".selector").datepicker({
   monthNamesShort: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
 });

Upvotes: 0

Arzon Barua
Arzon Barua

Reputation: 514

//jquery UI datepicker

Here MM show the full name of month

$("#datepicker").datepicker({
            changeMonth: true,
            changeYear: true,
            dateFormat: 'dd MM yy',
});

Upvotes: 1

Boris Brdarić
Boris Brdarić

Reputation: 4684

Even nicer solution would be to use monthNames from your locale object.

// jQuery UI datepicker
$("#datepicker").datepicker({
    monthNamesShort: $.datepicker.regional["en"].monthNames
});

Upvotes: 9

Renske
Renske

Reputation: 236

Maybe a little bit late but I was having the same problem at this moment and it was pretty easily fixed. Before you call the datepicker function get the monthnames array, put them in a new variable and change shortnames by calling on that variable:

var fullmonth_array = $.datepicker.regional['nl'].monthNames; // change 'nl' to your own language of course
$('input[name="date-of-birth"]').datepicker(
{
   changeYear               : true,
   changeMonth              : true,
   yearRange                : "-85:-18",
   maxDate                  : "-18Y",
   minDate                  : "-85Y",
   monthNamesShort          : fullmonth_array
   // other stuff
}

Upvotes: 16

jay.d
jay.d

Reputation: 23

You can extend the datepicker and "override" the offending function, passing in the long names.

$.extend($.datepicker, {
    __base__generateMonthYearHeader: $.datepicker._generateMonthYearHeader,

    _generateMonthYearHeader: function (inst,
                                        drawMonth,
                                        drawYear,
                                        minDate,
                                        maxDate,
                                        secondary,
                                        monthNames,
                                        monthNamesShort) {
        return $.datepicker.__base__generateMonthYearHeader(
            inst,
            drawMonth,
            drawYear,
            minDate,
            maxDate,
            secondary,
            monthNames,
            monthNames)
    }
});

This has the benefit of displaying the full names in the drop down but allowing the formatting specified in the settings/options when the input element is set with the selected date.

Upvotes: 1

A. Wolff
A. Wolff

Reputation: 74420

Dont find better way than updating UI datepicker, but that gives you the idea:

DEMO

var months = ["January", "February", "March", "April", "May", "June",
                  "July", "August", "September", "October", "November", "December"];
var uDatepicker = $.datepicker._updateDatepicker;
$.datepicker._updateDatepicker = function() {
    var ret = uDatepicker.apply(this, arguments);
    var $sel = this.dpDiv.find('select');
    $sel.find('option').each(function(i) {
        $(this).text(months[i]);
    });
    return ret;
};

$(function() {
    $("#id").datepicker({
        changeMonth: true,
        dateFormat: 'MM yy'
    });
});​

Upvotes: 1

Related Questions