JQuery UI datepicker date range

I am trying to set up two date selections, for example http://jqueryui.com/demos/datepicker/#date-range . But if you manually enter the date in this example, you can break the code. for example, select a date from a date, then the collector stops you from choosing a date to a date, but you can manually enter a date that is earlier.

I installed an example here http://jsfiddle.net/Ruhley/s3h5L/

+3
source share
2 answers
+12

, . ( ). ,

<script>    
$(function() {
    var dates = $( "#datepicker1, #datepicker2" ).datepicker({
        changeMonth: true, changeYear: true,dateFormat: "yy-mm-dd",


        beforeShow: function( ) {
            var other = this.id == "from" ? "#datepicker2" : "#datepicker1";
            var option = this.id == "from" ? "maxDate" : "minDate";
            var selectedDate = $(other).datepicker('getDate');

            $(this).datepicker( "option", option, selectedDate );
        }
    }).change(function(){
        var other = this.id == "from" ? "#datepicker2" : "#datepicker1";

        if ( $('#datepicker1').datepicker('getDate') > $('#datepicker2').datepicker('getDate') )
            $(other).datepicker('setDate', $(this).datepicker('getDate') );
    });
});
</script>
+1

Source: https://habr.com/ru/post/1780797/


All Articles