Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a jqueryui datepicker minDate after initialization?

I have two datepickers (jqueryui) and I would like to restrict the second inputs (minDate property) to the value selected in first. How should I do this? I wrote the following code, without success:

  $("#picker1").button().click(function() {
        var minDate = $( "#picker1" ).datepicker( "getDate" );
        $( "#picker2" ).datepicker( "option", "minDate", minDate );  
        $( "#picker2" ).datepicker( "refresh");  
        });

Can you help me with this?

Thanks!

like image 949
Alex Avatar asked Mar 18 '13 16:03

Alex


People also ask

How do you add a minDate on datepicker?

Syntax: $( ". selector" ). datepicker({ minDate: new Date(2007, 1 - 1, 1) });

How do you set a datepicker position?

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.

How do you set minDate on DateTimePicker?

Step 1: Create a DateTimePicker using the DateTimePicker() constructor is provided by the DateTimePicker class. // Creating a DateTimePicker DateTimePicker dt = new DateTimePicker(); Step 2: After creating DateTimePicker, set the MinDate property of the DateTimePicker provided by the DateTimePicker class.

How do I change the default date in datepicker?

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


2 Answers

Try

$('#p1, #p2').datepicker();

$('#p1').change(function(){
    $('#p2').datepicker('option', 'minDate', $('#p1').datepicker('getDate'))
});

Demo: Fiddle

like image 162
Arun P Johny Avatar answered Nov 15 '22 21:11

Arun P Johny


I suspect getDate returning string .You can try like this.

$("#picker1").button().click(function() {
        var minDate = $( "#picker1" ).datepicker( "getDate" );      
        $( "#picker2" ).datepicker( "option", "minDate",  new Date(minDate));  
        $( "#picker2" ).datepicker( "refresh");  
        });
like image 43
Suresh Atta Avatar answered Nov 15 '22 20:11

Suresh Atta