New Post has been published on Html Use
New Post has been published on http://www.htmluse.com/valideasy-jquery-plugin-for-form-validation/
Valideasy – jQuery Plugin for Form Validation
Never write complex JS script again to handle your form validation rules! With Valideasy, everything’s done via HTML attributes added to your form fields.
Load latest jQuery library
Load js/jquery-valideasy.min.js
Instantiate Valideasy on your form :
$('form').submit(function() var formIsValid = $(this).valideasy( options ); return formIsValid; );
For most forms, you won’t need extra configuration for Valideasy to work properly. In some cases though, you might need to change the default parameters to meet your specific needs. There are two ways to set parameters:
As data- attribute in the <form> element.
As argments when instantiating Valideasy in your JS file.
Let’s take an example with the mode parameter (described below), you can set it either in your form element:
<form data-valideasy-mode="unified">
Or when instantiating the plugin:
$(this).valideasy( mode: 'unified' );
Here is the full (but short) list of available parameters, along with their default values. To use them as data- attributes, simply prefix with data-valideasy-
Note Parameters expecting functions cannot be used as data- attributes.
defaults = mode: 'single', errorElementId: 'errors', disableFieldStyle: false, stepByStep: false, scrollToFirstError: false, singleFieldValidation: false, onValidateBefore: function() return; , onValidateAfter: function() return; ,
How error messages are displayed.
single: each message is located near its field
unified: all messages at the same place, one at a time
Indicates the ID of the field(s) supposed to display error messages.
in single mode, the error message will be inserted in the element with ID field_iderrorElementId. For example: nameerrors
in unified mode, all the error messages will be inserted in the same element, with specified ID errorElementId.
Set to true to stop adding the .error class to fields with errors
Set to true to stop validation at first error
Set to true to auto scroll to the first error field at the end of the validation process
Set to true to only perform validation on one field, instead of on the entire form.
For this to work, Valideasy must be instantiated on a field element.
As of version 2.2.1, you can hook to pre and post validation events to perform certain tasks. Available hooks are :
onValidateBefore
Triggered right before the validation process begins. This hook receives two parameters: the form element being validated, and the array of the plugin options.
onValidateAfter
Triggered right after the validation process ends. This hook receives three parameters: the form element being validated, the array of the plugin options, and the validation status.
Validation rules are specified in the class attribute of the field
Default value of the field must be specified both in the value attribute and in the title attribute
In single mode, every field must be accompagnied with an element with the ID fieldId_errorElementId and class .error-wrapper. Any error message triggered by this field will be inserted in that element.
In unified mode, an element with the ID errorElementId and class .error-wrapper should be placed somewhere in the page. The first error message triggered by a field in the form will be placed in that element.
<form novalidate action="/" method="post"> <input class="rules" id="name" title="Name" type="text" value="Name" /> <p id="name_errors" class="error-wrapper"></p> </form>