Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn on Today button on date picker

I am using a date picker from this source http://jqueryui.com/datepicker/#buttonbar , I am trying to let "Today" button on the button bar to be active, can any one help me please.

$(".datepicker").datepicker({
            showButtonPanel: true, closeText: 'Clear',
             gotoCurrent : true,
            changeMonth: true,
            changeYear: true,
            yearRange: '1900, 2300',
            dateFormat: _DateFormatDatePicker,             
            onSelect: function (dateText, inst) {
                dateAsString = dateText; //the first parameter of this function
                var dateAsObject = $(this).datepicker('getDate'); //the getDate method
                document.getElementById('<%=hdnTempDate.ClientID%>').value = dateText;
            }
like image 344
Alaa Avatar asked Jun 09 '13 09:06

Alaa


3 Answers

Try this:

$(".datepicker").datepicker({
    showOn: "button",
    showButtonPanel: true,
    buttonImage: buttonCalendar,
    buttonImageOnly: true,
    buttonText: ""
});

and call this js code in the pages where you have the calendar.

$.datepicker._gotoToday = function(id) { 
    $(id).datepicker('setDate', new Date()).datepicker('hide').blur(); 
};
like image 186
periback2 Avatar answered Nov 20 '22 17:11

periback2


Try this

$(function() {
    $( "#datepicker" ).datepicker({
        showButtonPanel: true
    });
});
like image 21
R M Shahidul Islam Shahed Avatar answered Nov 20 '22 17:11

R M Shahidul Islam Shahed


Enable the Buttons panel by: showButtonPanel: true. Then place the following code after your datepicker JS code:

var _gotoToday = jQuery.datepicker._gotoToday;
jQuery.datepicker._gotoToday = function(a){
    var target = jQuery(a);
    var inst = this._getInst(target[0]);
    _gotoToday.call(this, a);
    jQuery.datepicker._selectDate(a, jQuery.datepicker._formatDate(inst,inst.selectedDay, inst.selectedMonth, inst.selectedYear));
};
like image 2
Tahir Avatar answered Nov 20 '22 17:11

Tahir