Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5048 dpurdie 1
/**
2
 * jQuery Form Validator Module: JSconf
3
 * ------------------------------------------
4
 * Created by Victor Jonsson <http://www.victorjonsson.se>
5
 *
6
 * This module makes it possible to configure form validation using javascript
7
 *
8
 * @website http://formvalidator.net/#location-validators
9
 * @license Dual licensed under the MIT or GPL Version 2 licenses
10
 * @version 2.2.beta.69
11
 */
12
(function($) {
13
 
14
  "use strict";
15
 
16
  $.setupValidation = function(conf) {
17
    var $forms = $(conf.form || 'form');
18
    $.each(conf.validate || conf.validation || {}, function(elemRef, attr) {
19
        var $elem;
20
        if( elemRef[0] == '#' ) {
21
          $elem = $(elemRef);
22
        } else if( elemRef[0] == '.' ) {
23
          $elem = $forms.find(elemRef);
24
        } else {
25
          $elem = $forms.find('*[name="' +elemRef+ '"]');
26
        }
27
 
28
        $elem.attr('data-validation', attr.validation);
29
 
30
        $.each(attr, function(name, val) {
31
          if( name != 'validation' && val !== false) {
32
            if( val === true )
33
              val = 'true';
34
            $elem.valAttr(name, val);
35
          }
36
        });
37
    });
38
 
39
    $.validate(conf);
40
  };
41
 
42
})(jQuery);