1
0
-1

We have a form with fairly complex validation logic placed in a calculation function on  a data field. It's typically runs as it should, but we have found that the calculations can lag behind, and generate a false validation, where the data should return true. It typically comes good after a few moments. 


This is an example of the code. We have similar code in three other places to check that start and end times for booking rooms. Any ideas as to what may be causing the lag, and ways to get around it? Thanks!

-----------------------------------------------------------------------------------------------------------------------------------------------------

//Provide a value or calculation for this data field

var d = data.library ;
var h = data.room;
var od = data.bookingDate;
var st = data.endTime;

if (Util.isBlank(data.endTime)) return true;

//This section gets the date and turns it into the weekday (variable o = weekday)
var o = new Date()
odd = od.split("-")
o.setFullYear(odd[0],odd[1] - 1,odd[2])

var weekday = new Array(7);
weekday[0] = "Sunday";
weekday[1] = "Monday";
weekday[2] = "Tuesday";
weekday[3] = "Wednesday";
weekday[4] = "Thursday";
weekday[5] = "Friday";
weekday[6] = "Saturday";


o = weekday[o.getDay()]

//This is a function to test if the time entered matches the required time
var chkTime = function(TTime, ot, ct) {
TTime = TTime.replace('.',':');
TTime = TTime.split(':');
th = parseInt(TTime[0]);
tm = parseInt(TTime[1]);

ot = ot.split(':');
oth = parseInt(ot[0]);
otm = parseInt(ot[1]);

ct = ct.split(':');
cth = parseInt(ct[0]);
ctm = parseInt(ct[1]);

return (th > oth || th === oth && tm >= otm)
&& (th < cth || th === cth && tm <= ctm);
}


if (h === "Hub (opening hours only)" && (o === "Monday" || o === "Tuesday" || o === "Wednesday" || o === "Friday" )){
return chkTime(st, '10:00', "17:30")
}
if (h === "Hub (opening hours only)" && o === "Saturday"){
return chkTime(st, '10:00', "16:00")
}
if (h == "Hub (opening hours only)" && o == "Sunday"){
return false
}
if (h === "Mezzanine (available after hours)" || d == "Dickson" || d == "Kippax" || d == "Tuggeranong" || d == "Belconnen" || i == "Gungahlin Library Training Room 1 (available after hours)" || i == "Gungahlin Library Training Room 2 (available after hours)"){
return chkTime(st, '6:00', "22:00")
}
if ((h === "Gungahlin Library Conference Room 1 (available after hours)" || h === "Gungahlin Library Conference Room 2 (available after hours)") && (o === "Monday" || o === "Tuesday" || o === "Thursday" || o === "Friday" )){
return chkTime(st, '17:30', "22:00")
}
if ((h === "Gungahlin Library Conference Room 1 (available after hours)" || h === "Gungahlin Library Conference Room 2 (available after hours)") && (o == "Saturday" || o === "Sunday")){
return chkTime(st, '6:00', "22:00")
}
if ((h === "Gungahlin Library Conference Room 1 (available after hours)" || h === "Gungahlin Library Conference Room 2 (available after hours)") && (o === "Wednesday")){
return false
}
if (h === "Gungahlin Library Training Room 1 (available after hours)" || h === "Gungahlin Library Training Room 2 (available after hours)"){
return chkTime(st, '6:00', "22:00")
}
if ((h === "Gungahlin Library Meeting Room 1 (opening hours only)" || h === "Gungahlin Library Meeting Room 2 (opening hours only)") && (o === "Monday" || o === "Tuesday" || o === "Thursday" || o === "Friday" )){
return chkTime(st, '10:00', "17:30")
}
if ((h === "Gungahlin Library Meeting Room 1 (opening hours only)" || h === "Gungahlin Library Meeting Room 2 (opening hours only)") && o === "Wednesday"){
return chkTime(st, '10:00', "20:00")
}
if ((h === "Gungahlin Library Meeting Room 1 (opening hours only)" || h === "Gungahlin Library Meeting Room 2 (opening hours only)") && o === "Saturday"){
return chkTime(st, '10:00', "16:00")
}
if ((h === "Gungahlin Library Meeting Room 1 (opening hours only)" || h === "Gungahlin Library Meeting Room 2 (opening hours only)") && o === "Sunday"){
return chkTime(st, '12:00', "16:00")
}
if ((d === "WodenConf" || d === "WodenComm" ) && o === "Monday"){
return chkTime(st, '10:00', "20:00")
}
if ((d === "WodenConf" || d === "WodenComm" ) && (o === "Tuesday" || o == "Wednesday" || o == "Thursday" || o == "Friday" )){
return chkTime(st, '10:00', "17:30")
}
if ((d === "WodenConf" || d === "WodenComm" ) && o === "Saturday"){
return chkTime(st, '10:00', "16:00")
}
/*
if (d === "WodenComm" && o === "Sunday"){
return chkTime(st, '12:00', "16:00")
}
*/
if ((d === "WodenComm" || d === "WodenConf") && o === "Sunday"){
return chkTime(st, '12:00', "16:00")
}
console.log("fin")
return true

    CommentAdd your comment...