The problem is that when I clear the dates (by deleting the textbox values), th
My way to solve this problem
Change var 'controls' on ui.js
controls = (!inst.inline ? "<button type='button' class='ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all' data-handler='hide' data-event='click'>" +
this._get(inst, "closeText") + "</button>" + "<button type='button' class='ui-datepicker-close ui-datepicker-clear ui-state-default ui-priority-primary ui-corner-all' data-handler='hide' data-event='click'>" +
this._get(inst, "clearText") + "</button>" : "");
Then add a clearText var
this.regional[""] = { // Default regional settings
closeText: "Done", // Display text for close link
clearText: "Clear", // Display text for close link
prevText: "Prev", // Display text for previous month link
And before show function
$(".i_date").datepicker
(
{
beforeShow: function (input, inst)
{
setTimeout
(
function ()
{
$('.ui-datepicker-clear').bind('click', function() { $(input).val(''); });
},
0
);
}
}
);
Try changing the clearing code to:
$('#clearDates').on('click', function(){
dates.attr('value', '');
$("input[id$='dpFrom'], input[id$='dpTo']").datepicker( "option", "maxDate", null );
$("input[id$='dpFrom'], input[id$='dpTo']").datepicker( "option", "minDate", null );
});
Try This, This Will Add Clear Button On Jquery Calender That Will Clear Date.
$("#DateField").datepicker({
showButtonPanel: true,
closeText: 'Clear',
onClose: function (dateText, inst) {
if ($(window.event.srcElement).hasClass('ui-datepicker-close'))
{
document.getElementById(this.id).value = '';
}
}
});
A modified version of Leniel Macaferi's solution to account for the backspace key being a "page back" shortcut in IE8 when a text field does not have focus (which appears to be the case when datepicker is open).
It also uses val()
to clear the field since _clearDate(this)
did not work for me.
$("#clearDates").datepicker().keyup(function (e) {
// allow delete key (46) to clear the field
if (e.keyCode == 46)
$(this).val("");
// backspace key (8) causes 'page back' in IE8 when text field
// does not have focus, Bad IE!!
if (e.keyCode == 8)
e.stopPropagation();
});
$("#datepicker").datepicker({
showButtonPanel: true,
closeText: 'Clear',
onClose: function () {
var event = arguments.callee.caller.caller.arguments[0];
if ($(event.delegateTarget).hasClass('ui-datepicker-close')) {
$(this).val('');
}
}
});
Please try this solution it will work properly as I have tried
$('selector').datepicker('setStartDate', 0);
$('selector').datepicker('setEndDate', 0);
$('selector').datepicker('update');