ParsleyField Class
ParsleyField class manage each form field inside a validated Parsley form. Returns if field valid or not depending on its value and constraints Manage field error display and behavior, event triggers and more
Constructor
ParsleyField
()
Item Index
Methods
- addConstraint
- addConstraints
- addCustomConstraintMessage
- addError
- applyValidators
- bindHtml5Constraints
- bindValidationEvents
- destroy
- eventValidation
- generateHash
- getHash
- getLength
- getVal
- hasConstraints
- init
- isValid
- manageError
- manageErrorContainer
- manageValidationResult
- needsValidation
- removeConstraint
- removeError
- removeErrors
- reset
- ulErrorManagement
- updtConstraint
- updtConstraint
- validate
Methods
addConstraint
-
constraint
Dynamically add a new constraint to a field
Parameters:
-
constraint
Object{ name: requirements }
addConstraints
()
private
Attach field validators functions passed through data-api
addCustomConstraintMessage
-
constraint
Add custom constraint message, passed through data-API
Parameters:
-
constraint
Object
addError
-
{
Add li error
Parameters:
-
{
Objectminlength: "error message for minlength constraint" }
applyValidators
()
Mixed
Loop through every fields validators Adds errors after unvalid fields
Returns:
{Boolean} If field valid or not, null if not validated
bindHtml5Constraints
()
private
Bind some extra html5 types / validators
bindValidationEvents
()
private
Bind validation events on a field
destroy
()
private
Destroy parsley field instance
eventValidation
-
event
Called when validation is triggered by an event Do nothing if val.length < this.options.validationMinlength
Parameters:
-
event
ObjectjQuery event
generateHash
()
String
Hash management. Used for ul error
Returns:
5 letters unique hash
getHash
()
String
Public getHash accessor
Returns:
hash
getLength
()
Int
Get the length of a given value
Returns:
The length of the value
getVal
()
String
Returns field val needed for validation Special treatment for radio & checkboxes
Returns:
val
hasConstraints
()
Boolean
Return if field has constraints
Returns:
Is field has constraints or not
init
-
element
-
options
Set some properties, bind constraint validators and validation events
Parameters:
-
element
Object -
options
Object
isValid
()
Boolean
Return if field verify its constraints
Returns:
Is field valid or not
manageError
-
constraint
Add li / ul errors messages
Parameters:
-
constraint
Object
manageErrorContainer
()
Create ul error container
manageValidationResult
()
Boolean
Fired when all validators have be executed Returns true or false if field is valid or not Display errors messages below failed fields Adds parsley-success or parsley-error class on fields
Returns:
Is field valid or not
needsValidation
-
value
Check if value has changed since previous validation
Parameters:
-
value
Object
Returns:
removeConstraint
-
constraintName
Dynamically remove an existing constraint to a field.
Parameters:
-
constraintName
String
removeError
-
constraintName
Remove li / ul error
Parameters:
-
constraintName
StringMethod Name
removeErrors
()
Remove all ul / li errors
reset
()
Remove ul errors and parsley error or success classes
ulErrorManagement
()
private
Manage ul error Container
updtConstraint
-
constraint
Dynamically update an existing constraint to a field. Simple API: { name: requirements }
Parameters:
-
constraint
Object
updtConstraint
-
constraint
Dynamically update an existing constraint to a field. Complex API: { name: name, requirements: requirements, valid: boolean }
Parameters:
-
constraint
Object
validate
-
errorBubbling
Validate a field & display errors
Parameters:
-
errorBubbling
Booleanset to false if you just want valid boolean without error bubbling next to fields
Returns:
Is field valid or not