Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

changing minDate option in JQuery DatePicker not working

I have declared a date picker instance as follows:

    $("#datePickerId").datepicker(     { dateFormat: 'DD, d MM yy',       minDate: 0,       showOn: 'button',       buttonImage: '../../images/calendar.gif',       buttonImageOnly: true,       hideIfNoPrevNext: true     }    ); 

I now want to change to the minDate option so I do this:

$('#datePickerId').datepicker('option', 'minDate', 3); 

But nothing happens. Was I suppose to do anything else? What other possible causes could there be?

like image 703
Draco Avatar asked May 11 '09 09:05

Draco


People also ask

How do I remove my minDate on datepicker?

Try this $( "#MyDatepicker" ). datepicker( "option", "minDate", null) .

How do I change the pop up position of the jQuery datepicker control?

To change the position of the jQuery UI Datepicker just modify . ui-datepicker in the css file. The size of the Datepicker can also be changed in this way, just adjust the font size.

What is minDate and maxDate in jQuery datepicker?

If you like to restrict access of users to select a date within a range then there is minDate and maxDate options are available in jQuery UI. Using this you can set the date range of the Datepicker. After defining these options the other days will be disabled which are not in a defined range.

How can change date format in jQuery UI datepicker?

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


1 Answers

How to dynamically alter the minDate (after init)

The above answers address how to set the default minDate at init, but the question was actually how to dynamically alter the minDate, below I also clarify How to set the default minDate.

All that was wrong with the original question was that the minDate value being set should have been a string (don't forget the quotes):

$('#datePickerId').datepicker('option', 'minDate', '3'); 

minDate also accepts a date object and a common use is to have an end date you are trying to calculate so something like this could be useful:

$('#datePickerId').datepicker(     'option', 'minDate', new Date($(".datePop.start").val()) ); 

How to set the default minDate (at init)

Just answering this for best practice; the minDate option expects one of:

  1. a string in the current dateFormat OR
  2. number of days from today (e.g. +7) OR
  3. string of values and periods ('y' for years, 'm' for months, 'w' for weeks, 'd' for days, e.g. '-1y -1m')

@bogart setting the string to "0" is a solution as it satisfies option 2 above

$('#datePickerId').datepicker('minDate': '3'); 

jQuery UI docs for minDate

like image 182
Duncanmoo Avatar answered Oct 10 '22 09:10

Duncanmoo