Skip to content

Instantly share code, notes, and snippets.

@ppazos
Created July 30, 2020 04:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ppazos/55b350b3a88ada78e1085a4ca6db3650 to your computer and use it in GitHub Desktop.
Save ppazos/55b350b3a88ada78e1085a4ca6db3650 to your computer and use it in GitHub Desktop.
/*
using the jquery serializedArray from a form is very difficult to validate the
data because of the structure, passing that to an object results in a easier
to use structure for data validation, this is an example on hwo that works
*/
var params = $('#processed_form').serializeArray();
var params_obj = {};
$(params).each(function(i, field){
params_obj[field.name] = field.value;
});
if (params_obj.processed_status == 'accepted')
{
if (!params_obj.check_number || !params_obj.check_date)
{
// TODO: bootstrap alert inside the processed form
alert('The check number and date are required');
return false;
}
}
else if (params_obj.processed_status == 'partial')
{
if (!params_obj.check_number || !params_obj.check_date)
{
// TODO: bootstrap alert inside the processed form
alert('The check number and date are required');
return false;
}
if (!params_obj.total)
{
// TODO: bootstrap alert inside the processed form
alert('The total $ is required');
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment