Flatpickr验证startDate在endDate之前

时间:2019-11-21 23:38:35

标签: javascript jquery flatpickr

我有两个使用flatpickr的DateTime输入。看来普通的自定义验证不适用于输入。

这是我尝试过的。但是,表单仍然可以提交并将第一个日期更改为第二个日期

 // Validate that the start date is not after the end date
    var validateDates = function(startDate, endDate, endDateInput) {
        // Detect if the start and end date are valid (startDate is not after endDate) for create/edit modals
        // If end date is invalid, leave the displayed duration at 0
        getDifferenceInDays(startDate, endDate);

        if (startDate > endDate) {
            $('input[type="text"].eval-close-window-input')[1].setCustomValidity('End date must not be before start date.');
            $('input[type="text"].eval-close-window-input')[1].reportValidity();
            return false;

            // endDateInput.reportValidity()
        } else {
            $('input[type="text"].eval-close-window-input')[1];

            return true;
        }

    };

我要定位的输入是这两个输入中的第二个。

// The input that I originally created
<input type="hidden" id="open-window-747" name="open-window" class="ml-1 pl-2 form-check-inline small-selector flatpickr-input form-control input eval-open-window-input" value="2019-11-23 3:36">

// Targeting this input
<input class="form-control flatpickr-input input active eval-close-window-input flatpickr-input form-control input" placeholder="" type="text" readonly="readonly">



0 个答案:

没有答案