-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFValidation.js
62 lines (50 loc) · 1.24 KB
/
FValidation.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
(function($){
$.fn.Validation = function(options) {
var defaults = {
autosubmit: true,
onBefore:function(){},
onError:function(){},
onSuccess : function(){}
}
//Extend options
this.options = $.extend(defaults, options);
this.form = this;
var that = this;
this.form.bind("submit", function(){
return that.Submit();
});
return this;
},
$.fn.Submit = function( ){
this.options.onBefore.call(this,this);
if( this.isValid() ){
this.options.onSuccess.call(this,this.collection);
if( this.options.autosubmit ){
return true;
}else{
return false;
}
}
return false;
},
$.fn.isValid = function(){
var that = this;
this.collection = $("input[required=required]") ;
this.error = new Array();
$.each( this.collection, function(i,e){
if( e.value == '' ){
that.error.push( e );
}
});
if( that.error.length == 0 ){
return true;
}else{
$.each(this.error,function(i,e){
$(e).addClass('errorInput');
});
this.options.onError.call(this,this.error);
return false;
}
return false;
}
})(jQuery);