Created
July 15, 2019 16:26
-
-
Save OniAdekunle/0f591d4e58d4394d73a989d9c88a7a59 to your computer and use it in GitHub Desktop.
Datepicker disable past dates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<label for="from">From</label> | |
<input type="text" id="from" name="from"/> | |
<label for="to">to</label> | |
<input type="text" id="to" name="to"/> | |
<!-- | |
D'ont forget to Load jQuery and jQuery UI | |
--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var dateToday = new Date(); | |
var dates = $("#from, #to").datepicker({ | |
defaultDate: "+1w", | |
changeMonth: true, | |
numberOfMonths: 3, | |
minDate: dateToday, | |
onSelect: function(selectedDate) { | |
var option = this.id == "from" ? "minDate" : "maxDate", | |
instance = $(this).data("datepicker"), | |
date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings); | |
dates.not(this).datepicker("option", option, date); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/base/jquery-ui.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment