-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.validate-plus.js
38 lines (38 loc) · 1.91 KB
/
jquery.validate-plus.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
hsValidate: function( setting ){
setting = setting || {};
return $(this).each(function(){
var opts = $.extend({}, setting);
opts.rules = getValidateRulesByForm($(this), ( typeof opts.rules != 'undefined' ? opts.rules : null));
var mulitValids = $(this).find('.mulitValid');
if( mulitValids.length ){
$(this).attr('novalidate', true);
$(this).submit(function(){
var validator = $(this).validate( { rules: opts.rules} );
var mulitKeys = {};
mulitValids = $(this).find('.mulitValid');
mulitValids.each(function(i){
var oldName = $(this).data('name') ? $(this).data('name') : $(this).attr('name');
if( opts.rules[oldName] ){
if( mulitKeys[oldName] ) {
$(this).data('name', oldName).attr('name', oldName + '_' + i);
$(this).rules('add', opts.rules[oldName]);
} else
mulitKeys[oldName] = true;
}
});
var valid = $(this).valid();
if( valid ){
mulitValids.each(function(i){
var name = $(this).data('name');
if( name )
$(this).attr('name', name);
});
if( opts.submitHandler ) opts.submitHandler( this );
}
return false;
});
} else {
$(this).validate( opts );
}
});
}