Jquery UI datepicker reset date

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


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

thanks,

J.

+6
source share
4 answers

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

$(SELECTOR).datepicker('setDate', null); 
+6
source

The correct way to reset the date of a Datepicker widget is as follows:

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

Or like this:

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

Which is best for you.

+35
source

Clear button on calendar.

  $("#txtCalendar").datepicker({ showButtonPanel: true, closeText: 'Clear', onClose: function (dateText, obj) { if ($(window.event.srcElement).hasClass('ui-datepicker-close')) $("#txtCalendar").val(''); } }); 
+2
source

Just add this code.

 }).keyup(function(e) { if(e.keyCode == 8 || e.keyCode == 46) { $.datepicker._clearDate(this); } }); 

You can use backspace to clear the field, even if it has a read-only mode. A source

0
source

Source: https://habr.com/ru/post/946394/


All Articles