5
5
* Documentation and issue tracking on Github <https://github.com/victorjonsson/jQuery-Form-Validator/>
6
6
* Available for download at jQuery.com <http://plugins.jquery.com/project/jQueryFormValidtor/>
7
7
*
8
- * (c) 2011 Victor Jonsson, Sweden.
9
- * Dual licensed under the MIT or GPL Version 2 licenses
10
- *
8
+ * $license Creative Commons Erkännande-DelaLika 3.0 Unported License <http://creativecommons.org/licenses/by-sa/3.0/>
11
9
* $version 1.3.beta
10
+ * $stable 1.2 (https://github.com/victorjonsson/jQuery-Form-Validator/zipball/v1.2)
12
11
*/
13
-
14
12
( function ( $ ) {
15
13
$ . extend ( $ . fn , {
16
14
43
41
if ( help ) {
44
42
$ ( this )
45
43
. focus ( function ( ) {
46
- if ( $ ( this ) . parent ( ) . find ( '.jquery_form_help' ) . length == 0 ) {
47
- $ ( this ) . after (
44
+ var $element = $ ( this ) ;
45
+ if ( $element . parent ( ) . find ( '.jquery_form_help' ) . length == 0 ) {
46
+ $element . after (
48
47
$ ( '<span />' )
49
48
. addClass ( 'jquery_form_help' )
50
49
. text ( help )
55
54
} )
56
55
. blur ( function ( ) {
57
56
$ ( this ) . parent ( ) . find ( '.jquery_form_help' )
58
- . fadeOut ( 'slow' , function ( ) {
59
- $ ( this ) . remove ( ) ;
60
- } ) ;
57
+ . fadeOut ( 'slow' , function ( ) {
58
+ $ ( this ) . remove ( ) ;
59
+ } ) ;
61
60
} ) ;
62
61
}
63
62
} ) ;
78
77
if ( typeof attachKeyupEvent == 'undefined' )
79
78
attachKeyupEvent = true ;
80
79
80
+ var $element = $ ( this ) ;
81
+
81
82
var config = {
82
83
validationRuleAttribute : 'data-validation' ,
83
84
errorElementClass : 'error' , // Class that will be put on elements which value is invalid
92
93
else
93
94
language = jQueryFormUtils . LANG ;
94
95
95
- if ( jQueryFormUtils . defaultBorderColor == null && $ ( this ) . attr ( 'type' ) == 'text' )
96
- jQueryFormUtils . defaultBorderColor = $ ( this ) . css ( 'border-color' ) ;
96
+ var elementType = $element . attr ( 'type' ) ;
97
+ if ( jQueryFormUtils . defaultBorderColor == null && elementType != 'submit' && elementType != 'checkbox' && elementType != 'radio' )
98
+ jQueryFormUtils . defaultBorderColor = $element . css ( 'border-color' ) ;
97
99
98
100
// Remove possible error style applied by previous validation
99
- $ ( this )
101
+ $element
100
102
. removeClass ( config . errorElementClass )
101
103
. parent ( )
102
104
. find ( '.jquery_form_error_message' ) . remove ( ) ;
103
105
104
106
if ( config . borderColorOnError != '' )
105
- $ ( this ) . css ( 'border-color' , jQueryFormUtils . defaultBorderColor ) ;
107
+ $element . css ( 'border-color' , jQueryFormUtils . defaultBorderColor ) ;
106
108
107
- var validation = jQueryFormUtils . validateInput ( $ ( this ) , language , config ) ;
109
+ var validation = jQueryFormUtils . validateInput ( $element , language , config ) ;
108
110
109
111
if ( validation === true )
110
- $ ( this ) . unbind ( 'keyup' ) ;
112
+ $element . unbind ( 'keyup' ) ;
111
113
else {
112
- $ ( this )
114
+ $element
113
115
. addClass ( config . errorElementClass )
114
116
. parent ( )
115
117
. append ( '<span class="jquery_form_error_message">' + validation + '</span>' ) ;
116
118
117
119
if ( config . borderColorOnError != '' )
118
- $ ( this ) . css ( 'border-color' , config . borderColorOnError ) ;
120
+ $element . css ( 'border-color' , config . borderColorOnError ) ;
119
121
120
122
if ( attachKeyupEvent ) {
121
- $ ( this ) . bind ( 'keyup' , function ( ) {
123
+ $element . bind ( 'keyup' , function ( ) {
122
124
$ ( this ) . doValidate ( language , settings , false ) ;
123
125
} ) ;
124
126
}
192
194
var errorInputs = [ ] ;
193
195
194
196
/** Form instance */
195
- var form = this ;
197
+ var $ form = $ ( this ) ;
196
198
197
199
//
198
200
// Validate radio buttons
199
201
//
200
- $ ( this ) . find ( 'input[type=radio]' ) . each ( function ( ) {
202
+ $form . find ( 'input[type=radio]' ) . each ( function ( ) {
201
203
var validationRule = $ ( this ) . attr ( config . validationRuleAttribute ) ;
202
204
if ( typeof validationRule != 'undefined' && validationRule == 'required' ) {
203
205
var radioButtonName = $ ( this ) . attr ( 'name' ) ;
204
206
var isChecked = false ;
205
- form . find ( 'input[name=' + radioButtonName + ']' ) . each ( function ( ) {
207
+ $ form. find ( 'input[name=' + radioButtonName + ']' ) . each ( function ( ) {
206
208
if ( $ ( this ) . is ( ':checked' ) )
207
209
isChecked = true ;
208
210
} ) ;
217
219
//
218
220
// Validate element values
219
221
//
220
- $ ( this ) . find ( 'input,textarea,select' ) . each ( function ( ) {
222
+ $form . find ( 'input,textarea,select' ) . each ( function ( ) {
221
223
if ( ! ignoreInput ( $ ( this ) . attr ( 'name' ) , $ ( this ) . attr ( 'type' ) ) ) {
222
224
223
225
// memorize border color
228
230
$ ( this ) ,
229
231
language ,
230
232
config ,
231
- $ ( form )
233
+ $form
232
234
) ;
233
235
234
236
if ( valid !== true ) {
242
244
//
243
245
// Reset style and remove error class
244
246
//
245
- $ ( this ) . find ( 'input,textarea,select' )
247
+ $form . find ( 'input,textarea,select' )
246
248
. css ( 'border-color' , jQueryFormUtils . defaultBorderColor )
247
249
. removeClass ( config . errorElementClass ) ;
248
250
271
273
var messages = '<strong>' + language . errorTitle + '</strong>' ;
272
274
for ( var i = 0 ; i < errorMessages . length ; i ++ )
273
275
messages += '<br />* ' + errorMessages [ i ] ;
274
- $ ( this ) . children ( ) . eq ( 0 ) . before ( '<p class="' + config . errorMessageClass + '">' + messages + '</p>' ) ;
276
+
277
+ $form . children ( ) . eq ( 0 ) . before ( '<p class="' + config . errorMessageClass + '">' + messages + '</p>' ) ;
275
278
if ( config . scrollToTopOnError )
276
- $ ( window ) . scrollTop ( $ ( form ) . offset ( ) . top - 20 ) ;
279
+ $ ( window ) . scrollTop ( $form . offset ( ) . top - 20 ) ;
277
280
}
278
281
279
282
// Display error message below input field
@@ -781,5 +784,5 @@ jQueryFormUtils.lengthRestriction = function(inputElement, maxLengthElement) {
781
784
. focus ( function ( ) {
782
785
$ ( this ) . keyup ( ) ;
783
786
} )
784
- . keyup ( ) ;
787
+ . trigger ( 'keyup' ) ;
785
788
} ;
0 commit comments