Skip to content

Instantly share code, notes, and snippets.

@imknight
Last active December 20, 2015 07:39
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 imknight/6094510 to your computer and use it in GitHub Desktop.
Save imknight/6094510 to your computer and use it in GitHub Desktop.
custom function for Parsley before submit
$('#contactform').parsley({
//exclude input type , file ?
excluded: 'input[type=hidden]',
validators: {
// for #3 ,checking the input must have value , example dropdown list with "Select this" kind of option should be no value so that it can be skipped
checkdefault: function (val, checkdefault) {
if (val[0] === '') return false;
else return true;
}
},
messages: {
checkdefault: "This value should be a multiple of %s"
},
listeners: {
onFieldValidate: function (elem) {
//for #2 ,checking and make sure the parent div is not hidden
if (elem.parents('div.ishidden:eq(0)').length > 0 && !elem.parents('div.ishidden:eq(0)').is(':visible')) {
return true;
}
return false;
},
onFormSubmit: function (isFormValid, event, focusedField) {},
onFieldError: function (elem, constraint) {}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment