HOW TO develop and use my own plugin?

Discuss everything related to JavaScript Auto Form Validator. Questions and requests here.

Moderators: ne_moj, zewa, vadimako, ne_moj, zewa, vadimako

Site Admin
Site Admin
Posts: 5959
Joined: Jan 7th, '09, 23:18

HOW TO develop and use my own plugin?

Postby administrator » Jan 27th, '14, 16:46

You may develop and use your own plugins for specific validations.
Remember: plugins may be used with "attributes" mode only, not with "prefixes"!

To create your own plugin perform following steps:

1. Define a name for your plugin class, for example class for temperature validations : "temperature"

2. Create a file with such name (lowercase) in directory formvalidator/plugins/": temperature.js

3. Below the template for plugin class (only required properties and methods):

Code: Select all

Plugin_temperature = function()
    var _params = new Array(); /* leave empty if no additional parameters needed */

    /** Returns parameters  */
    this.getParams = function(){
        return _params;

    /** Validates given data */
    this.validate = function(validation_value, pparams){
        // here you add your code for temperature validation: "validation_value", using pparams (if needed)
        // for example:
        return (validation_value > 50) ? true : false;

    /** Returns error message */
    this.errorMessage = function(){
        return 'Error message';

4. Now load this plugin when you create FormValidator object:

Code: Select all

var jsFormValidator = new FormValidator();   

5. Usage :

Code: Select all

<input type="text" name="temp" title="Home Temperature" required="true" data-type="temperature" maxlength="10" />

Return to “JS Auto Form Validator”