Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery UI datepicker reset date

I have a datepicker that's on an input field, default date when I first open it is today's date, which is what I want.
However, when I select a date and I clear the input field, the datepicker still has the selected date on it, which I don't want

Does anyone have an idea why this happens and how I can prevent this behavior?

like image 227
J.Pip Avatar asked Jun 03 '13 10:06

J.Pip


People also ask

How can change date format in jQuery ui DatePicker?

inside the jQuery script code just paste the code. $( ". selector" ). datepicker({ dateFormat: 'yy-mm-dd' });

How do I change date format in picker?

Double-click the date picker, text box, or expression box control whose data you want to format.

How to add clear button in DatePicker?

How to add clear button with DatePicker? Clear button can be included in the DatePicker control. In the create event of DatePicker, clear button element should be appended in the input element and event for clearing the value should bind with the clear button element.


2 Answers

The proper way to reset the date of a Datepicker widget is like this:

$.datepicker._clearDate('#input_field_goes_here');

Or like this:

$('#input_field_goes_here').datepicker('setDate', null);

Whichever works best for you.

like image 158
silkfire Avatar answered Sep 17 '22 17:09

silkfire


See http://codepen.io/alexgill/pen/yOQrwV

$(SELECTOR).datepicker('setDate', null);
like image 34
Alex Gill Avatar answered Sep 19 '22 17:09

Alex Gill