# new VPValidator()
Validator instances are responsible for managing fieldsets. Validator instances are capable of dispatching validation on all fieldsets (and fields), allowing for a single "isValid" check.
Example
<form id="sample_form">
...
</form>
const Validator = new VP.Validator(
document.getElementById('sample_form'), <options>);
Extends
Classes
Methods
# addEventListener(event_name, callback)
Add an event listener
Parameters:
Name | Type | Description |
---|---|---|
event_name |
string | Name of the event |
callback |
EventCallback | Event callback to fire |
# addFieldset(fieldset, indexopt)
Add a fieldset instance to be tracked
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
fieldset |
VPFieldset | Fieldset to track |
|
index |
number |
<optional> |
Indicate the fieldset order to track by |
# addMessage(message, statusopt)
Adds a unique message to the $MessageNode
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
message |
The message to append |
||
status |
<optional> |
An optional class to append indicating message status |
- Overrides:
If the $MessageNode isn't set or isn't an HTMLElement
# addMessages(messages, statusopt)
Batch append messages
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
messages |
The messages to append |
||
status |
<optional> |
An optional class to append indicating message status |
If the $MessageNode isn't set or isn't an HTMLElement
# clearMessages()
Clear all messages from the $MessageNode (If set)
# createEvent(event_name, options) → {Event}
Helper for creating a new event, supporting IE9
Parameters:
Name | Type | Description |
---|---|---|
event_name |
string | Name of the event |
options |
EventOptions | Event options |
# createFieldset(el, options, fieldsopt)
Helper method for creating a new Fieldset to automatically track
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
el |
HTMLElement | Fieldset element |
|
options |
VPFieldsetOptions | Options to apply to the fieldset instance |
|
fields |
Array.<VPField> |
<optional> |
Fields to append to the fieldset |
# dispatchEvent(event, data) → {boolean}
Include support for passing data along event
Parameters:
Name | Type | Description |
---|---|---|
event |
Event | the Event object to dispatch |
data |
any | Data to be passed to the callback |
# findFieldsets(fieldsetOptionsopt)
Helper for automatically parsing child elements for Fieldsets
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
fieldsetOptions |
VPFieldsetOptions | Array.<VPFieldsetOptions> |
<optional> |
Options to apply to the found fieldsets. If array, options will apply based on index |
# generateMessageNode(anchoropt, posopt)
Generate a messageNode where messages can be added and removed in a managed way.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
anchor |
<optional> |
The anchor to use for the $MessageNode (Defaults to $MessageAnchor) |
|
pos |
<optional> |
The position to set $MessageNode inside the $MessageAnchor |
If anchor isn't an Element
If pos isn't a valid
# isElementVisible(element)
Helper method to determine if the element is visible within the DOM
Parameters:
Name | Type | Description |
---|---|---|
element |
HTMLElement | Element to test |
boolean
# isValid()
IsValid is a standard method for validating the internal state of a validator and all it's associated fieldsets (and fields). This method supports dynamic checks for determining if validation should be performed async or sync.
If any custom validation rules resolve async, validation will be performed async. Otherwise, all validation is performed synchronously. Optionally, You may enforce async validation through a validation option. This will enforce all validation is returned as a promise.
Further, this validation library is capable of short-circuit validation. Lazy validation will stop validation on the first instance of an error.
# removeEventListener(event_name, callback) → {EventCallback|null}
Remove an event listener
Parameters:
Name | Type | Description |
---|---|---|
event_name |
string | Name of the event |
callback |
EventCallback | The event callback to remove |
# removeFieldset(fieldset)
Remove a tracked fieldset from this validator
Parameters:
Name | Type | Description |
---|---|---|
fieldset |
VPFieldset | Fieldset instance to remove |
# removeMessage(message)
Remove a message
Parameters:
Name | Type | Description |
---|---|---|
message |
The message to remove |
If the $MessageNode isn't set or isn't an HTMLElement
# removeMessageNode()
Removes the $MessageNode from the $MessageAnchor
If the $MessageNode isn't set or isn't an HTMLElement