The onsubmit
event handler allows the submission to proceed if it is passed a true
value by the validation function, and does not allow the submission to proceed if it receives a false
value. In your case, the inner function is returning a true or false value, but this value is not being passed to the outer validateNewQuiz
function, so the true/false result of the validation is not being passed to the onsubmit
event handler. To fix this, just return the value of the CSV
function.
function validateNewQuiz()
{
var csvValidation = CSV.begin("#upload_csv").go(function(e,D)
{
if (e)
{
return console.log(e);
alert("Sorry, an error occured");
}
var s = "";
for (var i = 0; i <= D.rows.length - 1; i++)
{
s +=D.rows[i].join(',');
s += "\n";
}
var fullString = s;
if(/^(([^,]+,){4}[^,]+\n){3}$/.test(fullString))
{
return true;
}
else
{
return false;
}
});
return csvValidation;
}