Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show current day in the title of jquery datepicker

How can I show current full date in the title of jquery datepicker like this :

05 July 2015 because it show me just July 2015

enter image description here

like image 327
Hayi Avatar asked Jul 05 '15 13:07

Hayi


People also ask

How can I get current date in Datepicker?

On the All tab of the Property Sheet, make sure the Show Date Picker property is set to For dates. On the Data tab of the property sheet, type =Date() in the Default Value property for the field. Note: If you want to include the current time as well as the date, use the Now() function instead of Date().

What is minDate and maxDate in jQuery Datepicker?

If you like to restrict access of users to select a date within a range then there is minDate and maxDate options are available in jQuery UI. Using this you can set the date range of the Datepicker. After defining these options the other days will be disabled which are not in a defined range.

How do I use DateRangePicker?

Add DateRangePicker to the applicationAdd the HTML input element with an ID attribute as element for DateRangePicker to your index. html file. Import the DateRangePicker component to your app. ts and append it to the #element [src/app/app.


2 Answers

You could use a function like this in onSelect

function showDateInTitle(picker) {
    var span = picker.dpDiv[0].querySelector('.ui-datepicker-day'),
        df, month;
    if (span === null) {
        month = picker.dpDiv[0].querySelector('.ui-datepicker-month');
        if (!month) return;
        span = document.createElement('span');
        span.setAttribute('class', 'ui-datepicker-day');
        df = document.createDocumentFragment();
        df.appendChild(span);
        df.appendChild(document.createTextNode('\u00a0'));
        month.parentNode.insertBefore(
            df,
            month
        );
    }
    span.textContent = picker.selectedDay;
}

Still looking through API for a handler for after the datepicker is shown before choice is made


You can implement an afterShow as described here with a slight modification to get the instance

$(function() {
    $.datepicker._updateDatepicker_original = $.datepicker._updateDatepicker;
    $.datepicker._updateDatepicker = function(inst) {
        $.datepicker._updateDatepicker_original(inst);
        var afterShow = this._get(inst, 'afterShow');
        if (afterShow)
            afterShow.apply((inst.input ? inst.input[0] : null), [inst]);
    }
});

Now DEMO

like image 130
Paul S. Avatar answered Sep 30 '22 10:09

Paul S.


I couldn't find a non-hacky way of doing it, but changing the defaults config to the text you want to show might do it for you:

var defaults = {
  monthNames: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ]
};

var today = new Date();
var month = today.getMonth();
defaults.monthNames[month] = today.getDate() + ' ' +  defaults.monthNames[month];

$.datepicker.setDefaults(defaults);

Here is a working plnkr: http://plnkr.co/edit/gfp95VOchd4fhQOktIL3?p=preview

like image 32
yvesmancera Avatar answered Sep 30 '22 08:09

yvesmancera