Skip to content Skip to footer

Form script to allow the form submission on the basis of time slot selection.

Description:

This form script allows the form submission only when the selected time lot from the form matches the current time.

var flag = false
function validateTimeSlot(ws){
    var reggie = /(\d{4})-(\d{1,2})-(\d{1,2}) (\d{1,2})\:(\d{1,2})/;
    var reg = /(\d{2}):00 to (\d{2}):00/;
    dateArray = reggie.exec(datestring)
    var shift = ws.getWidgetValue("Shift_7");
    shift = JSON.parse(shift)
    if(ws.isWidgetVisible("Morning_Time_Slot") && shift[0] == "Morning"){
        var morningTS = ws.getWidgetValue("Morning_Time_Slot");
        var tsArray = reg.exec(morningTS);
    if (!(tsArray[1] <= dateArray[4] && tsArray[2] >= dateArray[4]))
    {
        if(flag == true){
        ws.setGeneralError(JSON.stringify({"t":"Validation Error","m":"please select correct time slot","tp":"error"}))
        }
        else{
        ws.showAlert(JSON.stringify({"t":"Error","m":"please select correct time slot","tp":"alert"}))
        }
    }
       else{
    settoggle(ws)
   } 
    }
    if(ws.isWidgetVisible("Afternoon_Time_Slot") && shift[0] == "Afternoon"){
        var Afternoonts = ws.getWidgetValue("Afternoon_Time_Slot");
        var tsArray = reg.exec(Afternoonts);
    if (!(tsArray[1] <= dateArray[4] && tsArray[2] >= dateArray[4]))
    {
        if(flag == true){
        ws.setGeneralError(JSON.stringify({"t":"Validation Error","m":"please select correct time slot","tp":"error"}))
        }
        else{
        ws.showAlert(JSON.stringify({"t":"Error","m":"please select correct time slot","tp":"alert"}))
        }
    }
        else{
    settoggle(ws)
       } 
    }
    if(ws.isWidgetVisible("Night_Time_Slot") && shift[0] == "Night"){
        var nightts = ws.getWidgetValue("Night_Time_Slot");
        var tsArray = reg.exec(nightts);
    if (!(tsArray[1] <= dateArray[4] && tsArray[2] >= dateArray[4]))
    {
        if(flag == true){
        ws.setGeneralError(JSON.stringify({"t":"Validation Error","m":"please select correct time slot","tp":"error"}))
        }
        else{
        ws.showAlert(JSON.stringify({"t":"Error","m":"please select correct time slot","tp":"alert"}))
        }
    }
       else{
    settoggle(ws)
   } 
    }
    if(ws.isWidgetVisible("General") && shift[0] == "General"){
        var generalts = ws.getWidgetValue("General");
        var tsArray = reg.exec(generalts);
    if (!(tsArray[1] <= dateArray[4] && tsArray[2] >= dateArray[4]))
    {
        if(flag == true){
        ws.setGeneralError(JSON.stringify({"t":"Validation Error","m":"please select correct time slot","tp":"error"}))
        }
        else{
        ws.showAlert(JSON.stringify({"t":"Error","m":"please select correct time slot","tp":"alert"}))
        }
    }
}
    else{
    settoggle(ws)
   } 
}
function on_submit(ws){
    flag = true;
    validateTimeSlot(ws)
    flag = false;
}

Was This Article Helpful?

0
0 Comments

There are no comments yet

Leave a comment

Your email address will not be published. Required fields are marked *

Close Bitnami banner
Bitnami