Skip to content

Instantly share code, notes, and snippets.

@carlossalas
Created October 11, 2017 17:40
Show Gist options
  • Save carlossalas/d2fe976e80460bcb48ab9b2e0a32b582 to your computer and use it in GitHub Desktop.
Save carlossalas/d2fe976e80460bcb48ab9b2e0a32b582 to your computer and use it in GitHub Desktop.
JS: Example Parsley Add Custom error
$('form input').each(function(i, input){
specific_field = $(input).parsley();
window.ParsleyUI.removeError(specific_field, 'serverError');
});
$.post('api/registro/guardar', serializeFormData, function(res){
if ( res.success )
{
callback();
}
else
{
if ( res.error_type == 'error_form_validation' )
{
for ( field in res.error_form_validation )
{
var error_message = res.error_form_validation[field],
specific_field = $('form input[name="'+field+'"]').parsley();
window.ParsleyUI.addError(specific_field, 'serverError', error_message);
}
}
}
Home.unblock();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment