Organize data submission if Javascript verification time fails

There is a time selection box in the form form. By default, the current time will be entered automatically after entering the page. However, if there is no time selected in the time box after filling in the form, the end time will be smaller than the actual time at that time. As a result, the background scheduled task cannot be refreshed, and the current task cannot be ended automatically. The time selection box is as follows:

First, define the function to judge the time input:

The first is the time selector function, and the second is the function to check the time

<script type="text/javascript">
        "autoApply": true, //Submit automatically after selecting a date; only works when time is not displayed timePicker:false
        singleDatePicker: true, //Single calendar
        showDropdowns: true, //Year month drop-down box
        timePicker: true, //Display time
        timePicker24Hour: true, //Time system
        timePickerSeconds: true, //Time to seconds
        startDate: moment().startOf('day'), //Set start date
        endDate: moment().startOf('day').add(6, 'hour'),
        minDate: moment(new Date()), //Set minimum date
        "opens": "center",
        showWeekNumbers: true,
        locale: {
            format: "YYYY-MM-DD HH:mm:ss", //Format display
            applyLabel: 'Determine', //Confirm button text
            cancelLabel: 'cancel', //Cancel button text
            daysOfWeek: ['day', 'One', 'Two', 'Three', 'Four', 'Five', 'Six'],
            monthNames: ['January', 'February', 'March', 'April', 'May', 'June',
                'July', 'August', 'September', 'October', 'November', 'December'
            firstDay: 1
    }, function (start) {
        console.log(start.format('YYYY-MM-DD HH:mm:ss'));

    function checkTime() {
        var end_time = document.getElementById("end_time").value;//Incoming time in time selection box
        var end = new Date(end_time);
        var now = new Date();//current time
        if (end.valueOf() > now.valueOf()) {
            return true;//Return true, indicating that the time input is reasonable
        } else {
            alert('The end time must be 10 minutes longer than the current actual time. Please reselect the end time...');
            return false;//Unreasonable time selection, data submission prohibited

Refer to the time check function in the submit button:

<div class="col-sm-offset-2 col-sm-10">
    <button type="submit" value="submit" onclick="return checkTime()" class="btn btn-outline-info btn-sm">Submission</button>

Now you can verify that the form cannot be submitted when the input time is less than the current actual time

Tags: Linux Javascript less

Posted on Sat, 09 Nov 2019 10:34:28 -0500 by jasoncable