Created
April 10, 2018 19:45
-
-
Save Cheslab/ce0dfbfc97fa3141bde8aad95042d717 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// jQuery UI is required | |
<form action="" class="form-filters"> | |
<label for="from">From</label> | |
<input type="text" id="from" name="from"> | |
<label for="to">to</label> | |
<input type="text" id="to" name="to"> | |
<script> | |
$(function() { | |
var dateFrom = new Date(); | |
var dateFormat = "dd.mm.yyyy", | |
from = $("#from") | |
.datepicker({ | |
changeMonth: true, | |
maxDate: dateFrom | |
}) | |
.on("change", function() { | |
to.datepicker("option", "minDate", getDate(this)); | |
var currentValueArray = $("#from").val().split(".").reverse(); | |
var currentValueString = ''; | |
currentValueArray.forEach(function(item) { | |
currentValueString = currentValueString + item + '-'; | |
}); | |
var currentValue = currentValueString.substring(0, 10); | |
to.datepicker('option', 'maxDate', new Date(currentValue)); | |
}), | |
to = $("#to").datepicker({ | |
changeMonth: true, | |
maxDate: dateFrom | |
}) | |
.on("change", function() { | |
from.datepicker("option", "maxDate", getDate(this)); | |
}); | |
function getDate(element) { | |
var date; | |
try { | |
date = $.datepicker.parseDate(dateFormat, element.value); | |
} catch (error) { | |
date = null; | |
} | |
return date; | |
} | |
}); | |
</script> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment