Parsley: Form Cheat Sheet

Options

PropertyDefaultDescription
data-parsley-namespace data-parsley-Choose the DOM-API you want to use for Parsley.
data-parsley-validate Bind Parsley validation to the form and its items with validation constraints
data-parsley-priority-enabled trueEither validate higher priority constraints first and stop on first failure (true), or validate all constraints simultaneously and show all the failing ones (false).
data-parsley-inputs input,
textarea,
select
When looking for fields within a form, Parsley uses this selector. The fields found will then be filtered using the excluded option below.
data-parsley-excludedinput[type=button],
input[type=submit],
input[type=reset],
input[type=hidden]
Form fields that won’t be validated by Parsley.
parsley-use-html5-constraintstrueBind or not supported HTML5 tags
parsley-show-errorstrueChoose to show or not Parsley error messages & success / errors classes
parsley-focusfirstSpecify which field will be focused first on form validation errors. firstlast and none allowed

Methods

MethodReturnsDescription
whenValid({group, force}) promiseReturns a jQuery promise that will be fulfilled if and only if the Form is valid. Does not affect UI nor fires events.
isValid({group, force})boolean or nullSimilar to whenValid but returns true if the promise is already fulfilled, false if already rejected, and null if the validation is still pending.
whenValidate({group, force})promiseValidate form. Prevents submission if not valid. Fires events and affects UI. You can only validate a certain group of fields by specifying optional group string parameter. If group is given, it only validates fields that belong to this group.
validate({group, force}) boolean or nullSame as whenValidate except it returns true if the promise is already fulfilled, false if already rejected, and null if the validation is still pending.
refresh() Forces a refresh of the form and its field. Parsley always refreshes before validation, but this may be helpful for dynamic changes that need to be applied immediately
reset() Reset UI for this form and for its fields.
destroy()Disable and destroy Parsley for this form and its fields

Leave a Reply

Your email address will not be published. Required fields are marked *