Skip to content Skip to footer

Form script to open the form in the given time slot

Description:

Form script to open the form in the given time slot. In the below form script the time slot is specified with the variable “min_hour & min_min”. In below form script I have mentioned “min_hour = 9 & min_min = 15”. So, Here we can submit this form from 09:00 to 09:15. Here we have used the time format of 24 hours so this time will be taken as morning time.

function val(ws, identifier) {
return ws.getWidgetValue(identifier);
}

function setGeneralError(ws, identifier, title, response, type, tag) {
if (response) {
var prompt = "";
if (identifier != "")
var prompt = ws.getWidgetPrompt(identifier) + "\n\n";
if (type == "error")
ws.setGeneralError(JSON.stringify({"t": title,"m": prompt + response,"tp": type}));
else if (type == "warning")
ws.setGeneralWarning(JSON.stringify({"t": title,"m": prompt + response,"tp": type}));
}
}

function showAlert(ws, identifier, title, response, type, tag) {
if (response) {
var prompt = "";
if (identifier != "")
var prompt = ws.getWidgetPrompt(identifier) + "\n\n";
ws.showAlert(JSON.stringify({"t": title,"m": prompt + response,"tp": type}));
} else {
ws.showAlert("");
}
}

function on_load(ws){
widget_identifier = 'Timestamp'
close = check_time_restriction(ws, widget_identifier)
if(close){
var json_value = JSON.stringify({'t':'Not able to fill form.','m':'Form can only be filled in between 9 to 9:15 AM'})
ws.closeForm(json_value);
}
}

function on_submit(ws){
  close = check_time_restriction(ws,'')
if(close){
setGeneralError(ws, '', 'General Error', 'Form can only be filled in between 9 to 9:15 AM', 'error',1);
var json_value = JSON.stringify({'t':'close form','m':'Form can only be filled in between 9 to 9:15 AM'})
ws.closeForm(json_value);
}
}

function check_time_restriction(ws,widget_identifier){
min_hour = 9
min_min = 15
if (widget_identifier){
var timestamp = val(ws,widget_identifier);
var reggie = /(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2})/;
var dateArray = reggie.exec(timestamp);
   timestamp_date = new Date(Date.UTC(dateArray[1],dateArray[2],dateArray[3],dateArray[4],dateArray[5],0,0))
}else{
timestamp_date = new Date()
}
    var hours = timestamp_date.getHours();
    var mins = timestamp_date.getMinutes();
if(min_hour != parseInt(hours) || parseInt(mins) > min_min){
return true
}
return 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