Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery Datepicker - no default date

I want to remove the default date in my JQuery Datepicker.

I try the following code:

$(this).datepicker({defaultDate: ''}); 

But it doesn't seem to work. Today's date is still selected as default.

like image 794
user352985 Avatar asked Sep 08 '10 13:09

user352985


People also ask

How do I change the default date in Datepicker?

Syntax: $(". selector"). datepicker( {defaultDate:"+6"} );

How can I get current date in Datepicker?

To set current date in control to which jQuery UI datepicker bind, use setDate() method. Pass date object which needs to be set as an argument to setDate() method. If you want to set it to current date then you can pass 'today' as argument.

How do you use a date picker?

Display the current date and time in a date pickerClick the Data tab. In the Data type box, click Date and Time (dateTime). Click Format. In the Date and Time Format dialog box, in the Display the time like this list, click the option that you want, and then click OK.


2 Answers

I got round the problem using a hidden altField:

<div id="DatePicker"></div> <input type="hidden" value="" name="Date" id="Date" /> 

and the following script:

<script>     $(function () {          $('#DatePicker').datepicker({             altField: '#Date', // ID of the hidden field             altFormat: 'dd/mm/yy'         });          // Remove the style for the default selected day (today)         $('.ui-datepicker-current-day').removeClass('ui-datepicker-current-day');          // Reset the current selected day         $('#Date').val('');     }); </script> 

Then, I used the hidden #Date field in my validation routines.

like image 130
Lee Gunn Avatar answered Sep 29 '22 21:09

Lee Gunn


None of the answers at the time of this writing really worked for me, so here was my solution cobbled from a couple of answers (for an inline datepicker).

    $('.calendar').datepicker("setDate", null); // this unsets the datepicker's internal selected date; it still shows a highlight on today's date that looks like a selected date though     $('.calendar').find(".ui-datepicker-current-day").removeClass("ui-datepicker-current-day"); // this actually removes the highlight 
like image 20
J. Polfer Avatar answered Sep 29 '22 23:09

J. Polfer