FormValidator class enables you to validate the form fields based on your defined rules
<form id='formId'>
<input type='text' name='Name' />
<input type='text' name='Age' />
</form>
<script>
let formObject = new FormValidator('#formId', {
rules: { Name: { required: true }, Age: { range: [18, 30] } };
});
formObject.validate();
</script>
string
Sets the defined css class to error fields
Defaults to ‘e-error’
string
Specify HTML element for error container
Defaults to ‘div’
string
Specify HTML element for error
Defaults to ‘label’
Option to display the error
Defaults to ErrorOption.Label
string
Ignores input fields based on the class name
Defaults to ‘e-hidden’
string
default locale variable
{ : }
Maps the input fields with validation rules
Defaults to {}
string
Sets the defined css class to valid fields
Defaults to ‘e-valid’
Adds the handler to the given event listener.
Parameter | Type | Description |
---|---|---|
eventName | string |
A String that specifies the name of the event |
handler | Function |
Specifies the call to run when the event occurs. |
Returns void
Add validation rules to the corresponding input element based on name
attribute.
Parameter | Type | Description |
---|---|---|
name | string |
name of form field. |
rules | Object |
Validation rules for the corresponding element. |
Returns void
Bind property changes immediately to components
Returns void
Destroy the form validator object and error elements.
Returns void
Get input element by name.
Parameter | Type | Description |
---|---|---|
name | string |
Input element name attribute value. |
Returns HTMLInputElement
Allows you to refresh the form validator base events to the elements inside the form.
Returns void
Removes the handler from the given event listener.
Parameter | Type | Description |
---|---|---|
eventName | string |
A String that specifies the name of the event to remove |
handler | Function |
Specifies the function to remove |
Returns void
Remove validation to the corresponding field based on name attribute. When no parameter is passed, remove all the validations in the form.
Parameter | Type | Description |
---|---|---|
name (optional) | string |
Input name attribute value. |
rules (optional) | string[] |
List of validation rules need to be remove from the corresponding element. |
Returns void
Reset the value of all the fields in form.
Returns void
Validate the current form values using defined rules.
Returns true
when the form is valid otherwise false
Parameter | Type | Description |
---|---|---|
selected (optional) | string |
Optional parameter to validate specified element. |
Returns boolean
EmitType<Event>
Trigger when a select/drop-down field is changed
EmitType<Event>
Triggers when a check box field is clicked
EmitType<HTMLElement|any>
Assigns the custom function to place the error message in the page.
EmitType<Event>
Triggers when a field’s focused out
EmitType<KeyboardEvent>
Trigger when keyup is triggered in any fields
EmitType<Event>
Triggers before form is being submitted
Triggers before validation starts
Triggers after validation is completed