beforeShow event not firing on jQueryUI Datepicker

后端 未结 6 957
你的背包
你的背包 2020-12-05 18:00

No matter what I try, I\'m not able to get the beforeShow event to fire on my datepicker. Here\'s my code:

$(\'#calendar\').datepicker({
inline: true,
dateF         


        
6条回答
  •  感情败类
    2020-12-05 18:36

    I wanted to use beforeShow to update the minumum date on an end date datepicker to reflect the date set in the start date datepicker. I have revewed a number of solutions posted here and elsewhere which were complicated. I may be missing something but the following quite straight forward code works for me.

    This resets the focus to the start date if none yet set and an attempt is made to enter an end date. If a start date has been set it sets the minimum date for the end _Date appropriately.

        $(function(){
        $("#start_Date").datepicker({
            changeMonth: true,
            changeYear: true,
            yearRange: "c-1:c+5",
            dateFormat: "dd-mm-yy"
        });
        $("#end_Date").datepicker({
            changeMonth: true,
            changeYear: true,
            yearRange: "c-1:c+5",
            dateFormat: "dd-mm-yy",
            beforeShow: end_Range
        });
    
        function end_Range(){
            if ($("#start_Date").datepicker("getDate") == null ){
                $("#start_Date").focus();
            } else {
                // set minimum date range
                $("#end_Date").datepicker("option", "minDate", new Date ($("#start_Date").datepicker("getDate")));
            };
        };
    });
    

    With date fields:

    
    
    

提交回复
热议问题