55* Documentation and issue tracking on Github <https://github.com/victorjonsson/jQuery-Form-Validator/>
66* Available for download at jQuery.com <http://plugins.jquery.com/project/jQueryFormValidtor/>
77*
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/>
119* $version 1.3.beta
10+ * $stable 1.2 (https://github.com/victorjonsson/jQuery-Form-Validator/zipball/v1.2)
1211*/
13-
1412( function ( $ ) {
1513 $ . extend ( $ . fn , {
1614
4341 if ( help ) {
4442 $ ( this )
4543 . 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 (
4847 $ ( '<span />' )
4948 . addClass ( 'jquery_form_help' )
5049 . text ( help )
5554 } )
5655 . blur ( function ( ) {
5756 $ ( this ) . parent ( ) . find ( '.jquery_form_help' )
58- . fadeOut ( 'slow' , function ( ) {
59- $ ( this ) . remove ( ) ;
60- } ) ;
57+ . fadeOut ( 'slow' , function ( ) {
58+ $ ( this ) . remove ( ) ;
59+ } ) ;
6160 } ) ;
6261 }
6362 } ) ;
7877 if ( typeof attachKeyupEvent == 'undefined' )
7978 attachKeyupEvent = true ;
8079
80+ var $element = $ ( this ) ;
81+
8182 var config = {
8283 validationRuleAttribute : 'data-validation' ,
8384 errorElementClass : 'error' , // Class that will be put on elements which value is invalid
9293 else
9394 language = jQueryFormUtils . LANG ;
9495
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' ) ;
9799
98100 // Remove possible error style applied by previous validation
99- $ ( this )
101+ $element
100102 . removeClass ( config . errorElementClass )
101103 . parent ( )
102104 . find ( '.jquery_form_error_message' ) . remove ( ) ;
103105
104106 if ( config . borderColorOnError != '' )
105- $ ( this ) . css ( 'border-color' , jQueryFormUtils . defaultBorderColor ) ;
107+ $element . css ( 'border-color' , jQueryFormUtils . defaultBorderColor ) ;
106108
107- var validation = jQueryFormUtils . validateInput ( $ ( this ) , language , config ) ;
109+ var validation = jQueryFormUtils . validateInput ( $element , language , config ) ;
108110
109111 if ( validation === true )
110- $ ( this ) . unbind ( 'keyup' ) ;
112+ $element . unbind ( 'keyup' ) ;
111113 else {
112- $ ( this )
114+ $element
113115 . addClass ( config . errorElementClass )
114116 . parent ( )
115117 . append ( '<span class="jquery_form_error_message">' + validation + '</span>' ) ;
116118
117119 if ( config . borderColorOnError != '' )
118- $ ( this ) . css ( 'border-color' , config . borderColorOnError ) ;
120+ $element . css ( 'border-color' , config . borderColorOnError ) ;
119121
120122 if ( attachKeyupEvent ) {
121- $ ( this ) . bind ( 'keyup' , function ( ) {
123+ $element . bind ( 'keyup' , function ( ) {
122124 $ ( this ) . doValidate ( language , settings , false ) ;
123125 } ) ;
124126 }
192194 var errorInputs = [ ] ;
193195
194196 /** Form instance */
195- var form = this ;
197+ var $ form = $ ( this ) ;
196198
197199 //
198200 // Validate radio buttons
199201 //
200- $ ( this ) . find ( 'input[type=radio]' ) . each ( function ( ) {
202+ $form . find ( 'input[type=radio]' ) . each ( function ( ) {
201203 var validationRule = $ ( this ) . attr ( config . validationRuleAttribute ) ;
202204 if ( typeof validationRule != 'undefined' && validationRule == 'required' ) {
203205 var radioButtonName = $ ( this ) . attr ( 'name' ) ;
204206 var isChecked = false ;
205- form . find ( 'input[name=' + radioButtonName + ']' ) . each ( function ( ) {
207+ $ form. find ( 'input[name=' + radioButtonName + ']' ) . each ( function ( ) {
206208 if ( $ ( this ) . is ( ':checked' ) )
207209 isChecked = true ;
208210 } ) ;
217219 //
218220 // Validate element values
219221 //
220- $ ( this ) . find ( 'input,textarea,select' ) . each ( function ( ) {
222+ $form . find ( 'input,textarea,select' ) . each ( function ( ) {
221223 if ( ! ignoreInput ( $ ( this ) . attr ( 'name' ) , $ ( this ) . attr ( 'type' ) ) ) {
222224
223225 // memorize border color
228230 $ ( this ) ,
229231 language ,
230232 config ,
231- $ ( form )
233+ $form
232234 ) ;
233235
234236 if ( valid !== true ) {
242244 //
243245 // Reset style and remove error class
244246 //
245- $ ( this ) . find ( 'input,textarea,select' )
247+ $form . find ( 'input,textarea,select' )
246248 . css ( 'border-color' , jQueryFormUtils . defaultBorderColor )
247249 . removeClass ( config . errorElementClass ) ;
248250
271273 var messages = '<strong>' + language . errorTitle + '</strong>' ;
272274 for ( var i = 0 ; i < errorMessages . length ; i ++ )
273275 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>' ) ;
275278 if ( config . scrollToTopOnError )
276- $ ( window ) . scrollTop ( $ ( form ) . offset ( ) . top - 20 ) ;
279+ $ ( window ) . scrollTop ( $form . offset ( ) . top - 20 ) ;
277280 }
278281
279282 // Display error message below input field
@@ -781,5 +784,5 @@ jQueryFormUtils.lengthRestriction = function(inputElement, maxLengthElement) {
781784 . focus ( function ( ) {
782785 $ ( this ) . keyup ( ) ;
783786 } )
784- . keyup ( ) ;
787+ . trigger ( 'keyup' ) ;
785788} ;
0 commit comments