Search code examples
jqueryjquery-uidatepickerjquery-ui-datepicker

Set minDate in Jquery


I want how to set minDate. I use this

$(function () {
    $("#dph-entry").datepicker('option', 'minDate', new Date(2017, 3, 27));
});

the input

<input type='text' class="con-input" id='dph-entry' placeholder="Entrada"/>

but doesn't works


Solution

  • You need to initialize datepicker() first. Then only option's can be set.

    $("#dph-entry").datepicker();
    $("#dph-entry").datepicker('option', 'minDate', new Date(2017, 3, 27));
    

    Better pass options while initializing

    $("#dph-entry").datepicker({'minDate': new Date(2017, 3, 27)});
    

    $(function() {
      $("#dph-entry").datepicker({
        'minDate': new Date(2017, 3, 27)
      });
    });
    <link href="https://code.jquery.com/ui/jquery-ui-git.css" rel="stylesheet" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
    <input type='text' class="con-input" id='dph-entry' placeholder="Entrada" />