Skip to content

Instantly share code, notes, and snippets.

@gladiatorAsh
Created June 18, 2015 11:02
Show Gist options
  • Save gladiatorAsh/db5589443c8a6a694282 to your computer and use it in GitHub Desktop.
Save gladiatorAsh/db5589443c8a6a694282 to your computer and use it in GitHub Desktop.
FullPageValidation
function validateDetails() {
/**
Clear all errors at the start
*/
for (i = 0; i < objValidationFailed.length; i++) {
$(objValidationFailed[i]).removeClass('error');
}
validated = true;
elementsToValidate = [];
objValidationFailed = [];
$('#divError').html('');
errorHtml = '<div><b><u>Please correct below errors:- </u></b><br/><ul>';
$('.required-val').each(function () {
elementsToValidate.push(this);
});
$('.number').each(function () {
//Check whether element is already in array
if ($.inArray(this, elementsToValidate) === -1) {
elementsToValidate.push(this);
}
});
$('.notZero').each(function () {
//Check whether element is already in array
if ($.inArray(this, elementsToValidate) === -1) {
elementsToValidate.push(this);
}
});
for (i = 0; i < elementsToValidate.length; i++) {
if ($(elementsToValidate[i]).hasClass('required-val')) {
CheckRequired($(elementsToValidate[i]));
}
if ($(elementsToValidate[i]).hasClass('number')) {
//Validate other than required
CheckNumber($(elementsToValidate[i]));
}
if ($(elementsToValidate[i]).hasClass('notZero')) {
//Validate other than required
CheckGreaterThanZero($(elementsToValidate[i]));
}
}
//Reset i
i = 0;
//Iterate over failed validation objects and fetch localized error messages
for (i = 0; i < objValidationFailed.length; i++) {
errorHtml += "<li>" +[lang][$(objValidationFailed[i]).attr('id')] + "</li>";
}
//Add closing tags
errorHtml += "</ul></div>";
if (!validated) {
$('#divError').html(errorHtml);
// toastr.error(errorHtml);
}
//else {
//Once validated, save data
//sdecCommonVM.saveData();
//}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment