Bug Tracker

Ticket #2908: JqueryValidate-CustomMetaMessages-unix.patch

File JqueryValidate-CustomMetaMessages-unix.patch, 77.1 kB (added by DaneOConnor, 8 months ago)
  • demo/custom-messages-metadata-demo.htm

     
     1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
     2<html xmlns="http://www.w3.org/1999/xhtml"> 
     3<head> 
     4<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> 
     5<title>jQuery validation plug-in - comment form example</title> 
     6 
     7<link rel="stylesheet" type="text/css" media="screen" href="css/screen.css" /> 
     8 
     9<script src="../lib/jquery.js" type="text/javascript"></script> 
     10<script src="../jquery.validate.js" type="text/javascript"></script> 
     11<script src="../lib/jquery.metadata.js" type="text/javascript"></script> 
     12 
     13<!-- for styling the form --> 
     14<script src="js/cmxforms.js" type="text/javascript"></script> 
     15 
     16<script type="text/javascript"> 
     17$(document).ready(function() { 
     18    $("#commentForm").validate({meta: "validate"}); 
     19    $("#commentForm2").validate(); 
     20    $("#commentForm3").validate({ 
     21                                messages:{ 
     22                                        email:{  
     23                                            required:'Enter this!' 
     24                                        } 
     25                                    }        
     26                                }); 
     27 
     28}); 
     29</script> 
     30 
     31<style type="text/css"> 
     32form { width: 500px; } 
     33form label { width: 250px; } 
     34form label.error,  
     35form input.submit { margin-left: 253px; } 
     36</style> 
     37 
     38</head> 
     39<body> 
     40<!-- Custom messages with custom "meta" setting --> 
     41<form class="cmxform" id="commentForm" method="post" action=""> 
     42    <fieldset> 
     43        <legend>Please enter your email address</legend> 
     44        <p> 
     45 
     46            <label for="cemail">E-Mail *</label> 
     47            <input id="cemail" name="email" class="{validate:{required:true, email:true, messages:{required:'Please enter your email address', email:'Please enter a valid email address'}}}"/> 
     48        </p> 
     49        <p> 
     50            <input class="submit" type="submit" value="Submit"/> 
     51        </p> 
     52    </fieldset> 
     53</form> 
     54<!-- Custom messages with default "meta" setting --> 
     55<form class="cmxform" id="commentForm2" method="post" action=""> 
     56    <fieldset> 
     57        <legend>Please enter your email address</legend> 
     58        <p> 
     59 
     60            <label for="cemail">E-Mail *</label> 
     61            <input id="cemail" name="email" class="{required:true, email:true, messages:{required:'Please enter your email address', email:'Please enter a valid email address'}}"/> 
     62        </p> 
     63        <p> 
     64            <input class="submit" type="submit" value="Submit"/> 
     65        </p> 
     66    </fieldset> 
     67</form> 
     68<!-- Custom message for "required" in metadata is overriden by a validate option --> 
     69<form class="cmxform" id="commentForm3" method="post" action=""> 
     70    <fieldset> 
     71        <legend>Please enter your email address</legend> 
     72        <p> 
     73 
     74            <label for="cemail">E-Mail *</label> 
     75            <input id="cemail" name="email" class="{required:true, email:true, messages:{required:'Please enter your email address', email:'Please enter a valid email address'}}"/> 
     76        </p> 
     77        <p> 
     78            <input class="submit" type="submit" value="Submit"/> 
     79        </p> 
     80    </fieldset> 
     81</form> 
     82 
     83 
     84</body> 
     85</html> 
     86 No newline at end of file 
  • jquery.validate.js

     
    1 /* 
    2  * jQuery validation plug-in 1.3 
    3  * 
    4  * http://bassistance.de/jquery-plugins/jquery-plugin-validation/ 
    5  * http://docs.jquery.com/Plugins/Validation 
    6  * 
    7  * Copyright (c) 2006 - 2008 Jörn Zaefferer 
    8  * 
    9  * $Id$ 
    10  * 
    11  * Dual licensed under the MIT and GPL licenses: 
    12  *   http://www.opensource.org/licenses/mit-license.php 
    13  *   http://www.gnu.org/licenses/gpl.html 
    14  */ 
    15  
    16 jQuery.extend(jQuery.fn, { 
    17     // http://docs.jquery.com/Plugins/Validation/validate 
    18     validate: function( options ) { 
    19          
    20         // if nothing is selected, return nothing; can't chain anyway 
    21         if (!this.length) { 
    22             options && options.debug && window.console && console.warn( "nothing selected, can't validate, returning nothing" ); 
    23             return; 
    24         } 
    25          
    26         // check if a validator for this form was already created 
    27         var validator = jQuery.data(this[0], 'validator'); 
    28         if ( validator ) { 
    29             return validator; 
    30         } 
    31          
    32         validator = new jQuery.validator( options, this[0] ); 
    33         jQuery.data(this[0], 'validator', validator);  
    34          
    35         if ( validator.settings.onsubmit ) { 
    36          
    37             // allow suppresing validation by adding a cancel class to the submit button 
    38             this.find(".cancel:submit").click(function() { 
    39                 validator.cancelSubmit = true; 
    40             }); 
    41          
    42             // validate the form on submit 
    43             this.submit( function( event ) { 
    44                 if ( validator.settings.debug ) 
    45                     // prevent form submit to be able to see console output 
    46                     event.preventDefault(); 
    47                      
    48                 function handle() { 
    49                     if ( validator.settings.submitHandler ) { 
    50                         validator.settings.submitHandler.call( validator, validator.currentForm ); 
    51                         return false; 
    52                     } 
    53                     return true; 
    54                 } 
    55                      
    56                 // prevent submit for invalid forms or custom submit handlers 
    57                 if ( validator.cancelSubmit ) { 
    58                     validator.cancelSubmit = false; 
    59                     return handle(); 
    60                 } 
    61                 if ( validator.form() ) { 
    62                     if ( validator.pendingRequest ) { 
    63                         validator.formSubmitted = true; 
    64                         return false; 
    65                     } 
    66                     return handle(); 
    67                 } else { 
    68                     validator.focusInvalid(); 
    69                     return false; 
    70                 } 
    71             }); 
    72         } 
    73          
    74         return validator; 
    75     }, 
    76     // http://docs.jquery.com/Plugins/Validation/valid 
    77     valid: function() { 
    78         if ( jQuery(this[0]).is('form')) { 
    79             return this.validate().form(); 
    80         } else { 
    81             var valid = false; 
    82             var validator = jQuery(this[0].form).validate(); 
    83             this.each(function() { 
    84                 valid |= validator.element(this); 
    85             }); 
    86             return valid; 
    87         } 
    88     }, 
    89     // attributes: space seperated list of attributes to retrieve and remove 
    90     removeAttrs: function(attributes) { 
    91         var result = {}, 
    92             $element = this; 
    93         $.each(attributes.split(/\s/), function() { 
    94             result[this] = $element.attr(this); 
    95             $element.removeAttr(this); 
    96         }); 
    97         return result; 
    98     }, 
    99     // http://docs.jquery.com/Plugins/Validation/rules 
    100     rules: function(command, argument) { 
    101         var element = this[0]; 
    102          
    103         if (command) { 
    104             var staticRules = jQuery.data(element.form, 'validator').settings.rules; 
    105             var existingRules = jQuery.validator.staticRules(element); 
    106             switch(command) { 
    107             case "add": 
    108                 $.extend(existingRules, jQuery.validator.normalizeRule(argument)); 
    109                 staticRules[element.name] = existingRules; 
    110                 break; 
    111             case "remove": 
    112                 if (!argument) { 
    113                     delete staticRules[element.name]; 
    114                     return existingRules; 
    115                 } 
    116                 var filtered = {}; 
    117                 $.each(argument.split(/\s/), function(index, method) { 
    118                     filtered[method] = existingRules[method]; 
    119                     delete existingRules[method]; 
    120                 }); 
    121                 return filtered; 
    122             } 
    123         } 
    124          
    125         var data = jQuery.validator.normalizeRules( 
    126         jQuery.extend( 
    127             {}, 
    128             jQuery.validator.metadataRules(element), 
    129             jQuery.validator.classRules(element), 
    130             jQuery.validator.attributeRules(element), 
    131             jQuery.validator.staticRules(element) 
    132         ), element); 
    133          
    134         // make sure required is at front 
    135         if (data.required) { 
    136             var param = data.required; 
    137             delete data.required; 
    138             data = $.extend({required: param}, data); 
    139         } 
    140          
    141         return data; 
    142     }, 
    143     // destructive add 
    144     push: function( t ) { 
    145         return this.setArray( this.add(t).get() ); 
    146     } 
    147 }); 
    148  
    149 // Custom selectors 
    150 jQuery.extend(jQuery.expr[":"], { 
    151     // http://docs.jquery.com/Plugins/Validation/blank 
    152     blank: function(a) {return !jQuery.trim(a.value);}, 
    153     // http://docs.jquery.com/Plugins/Validation/filled 
    154     filled: function(a) {return !!jQuery.trim(a.value);}, 
    155     // http://docs.jquery.com/Plugins/Validation/unchecked 
    156     unchecked: function(a) {return !a.checked;} 
    157 }); 
    158  
    159  
    160 jQuery.format = function(source, params) { 
    161     if ( arguments.length == 1 )  
    162         return function() { 
    163             var args = jQuery.makeArray(arguments); 
    164             args.unshift(source); 
    165             return jQuery.format.apply( this, args ); 
    166         }; 
    167     if ( arguments.length > 2 && params.constructor != Array  ) { 
    168         params = jQuery.makeArray(arguments).slice(1); 
    169     } 
    170     if ( params.constructor != Array ) { 
    171         params = [ params ]; 
    172     } 
    173     jQuery.each(params, function(i, n) { 
    174         source = source.replace(new RegExp("\\{" + i + "\\}", "g"), n); 
    175     }); 
    176     return source; 
    177 }; 
    178  
    179 // constructor for validator 
    180 jQuery.validator = function( options, form ) { 
    181     this.settings = jQuery.extend( {}, jQuery.validator.defaults, options ); 
    182     this.currentForm = form; 
    183     this.init(); 
    184 }; 
    185  
    186 jQuery.extend(jQuery.validator, { 
    187  
    188     defaults: { 
    189         messages: {}, 
    190         groups: {}, 
    191         rules: {}, 
    192         errorClass: "error", 
    193         errorElement: "label", 
    194         focusInvalid: true, 
    195         errorContainer: jQuery( [] ), 
    196         errorLabelContainer: jQuery( [] ), 
    197         onsubmit: true, 
    198         ignore: [], 
    199         onfocusin: function(element) { 
    200             this.lastActive = element; 
    201                  
    202             // hide error label and remove error class on focus if enabled 
    203             if ( this.settings.focusCleanup && !this.blockFocusCleanup ) { 
    204                 this.settings.unhighlight && this.settings.unhighlight.call( this, element, this.settings.errorClass ); 
    205                 this.errorsFor(element).hide(); 
    206             } 
    207         }, 
    208         onfocusout: function(element) { 
    209             if ( !this.checkable(element) && (element.name in this.submitted || !this.optional(element)) ) { 
    210                 this.element(element); 
    211             } 
    212         }, 
    213         onkeyup: function(element) { 
    214             if ( element.name in this.submitted || element == this.lastElement ) { 
    215                 this.element(element); 
    216             } 
    217         }, 
    218         onclick: function(element) { 
    219             if ( element.name in this.submitted ) 
    220                 this.element(element); 
    221         }, 
    222         highlight: function( element, errorClass ) { 
    223             jQuery( element ).addClass( errorClass ); 
    224         }, 
    225         unhighlight: function( element, errorClass ) { 
    226             jQuery( element ).removeClass( errorClass ); 
    227         } 
    228     }, 
    229  
    230     // http://docs.jquery.com/Plugins/Validation/Validator/setDefaults 
    231     setDefaults: function(settings) { 
    232         jQuery.extend( jQuery.validator.defaults, settings ); 
    233     }, 
    234  
    235     messages: { 
    236         required: "This field is required.", 
    237         remote: "Please fix this field.", 
    238         email: "Please enter a valid email address.", 
    239         url: "Please enter a valid URL.", 
    240         date: "Please enter a valid date.", 
    241         dateISO: "Please enter a valid date (ISO).", 
    242         dateDE: "Bitte geben Sie ein gültiges Datum ein.", 
    243         number: "Please enter a valid number.", 
    244         numberDE: "Bitte geben Sie eine Nummer ein.", 
    245         digits: "Please enter only digits", 
    246         creditcard: "Please enter a valid credit card.", 
    247         equalTo: "Please enter the same value again.", 
    248         accept: "Please enter a value with a valid extension.", 
    249         maxlength: jQuery.format("Please enter no more than {0} characters."), 
    250         maxLength: jQuery.format("Please enter no more than {0} characters."), 
    251         minlength: jQuery.format("Please enter at least {0} characters."), 
    252         minLength: jQuery.format("Please enter at least {0} characters."), 
    253         rangelength: jQuery.format("Please enter a value between {0} and {1} characters long."), 
    254         rangeLength: jQuery.format("Please enter a value between {0} and {1} characters long."), 
    255         rangeValue: jQuery.format("Please enter a value between {0} and {1}."), 
    256         range: jQuery.format("Please enter a value between {0} and {1}."), 
    257         maxValue: jQuery.format("Please enter a value less than or equal to {0}."), 
    258         max: jQuery.format("Please enter a value less than or equal to {0}."), 
    259         minValue: jQuery.format("Please enter a value greater than or equal to {0}."), 
    260         min: jQuery.format("Please enter a value greater than or equal to {0}.") 
    261     }, 
    262      
    263     autoCreateRanges: false, 
    264      
    265     prototype: { 
    266          
    267         init: function() { 
    268             this.labelContainer = jQuery(this.settings.errorLabelContainer); 
    269             this.errorContext = this.labelContainer.length && this.labelContainer || jQuery(this.currentForm); 
    270             this.containers = jQuery(this.settings.errorContainer).add( this.settings.errorLabelContainer ); 
    271             this.submitted = {}; 
    272             this.valueCache = {}; 
    273             this.pendingRequest = 0; 
    274             this.pending = {}; 
    275             this.invalid = {}; 
    276             this.reset(); 
    277              
    278             var groups = (this.groups = {}); 
    279             jQuery.each(this.settings.groups, function(key, value) { 
    280                 jQuery.each(value.split(/\s/), function(index, name) { 
    281                     groups[name] = key; 
    282                 }); 
    283             }); 
    284             var rules = this.settings.rules; 
    285             jQuery.each(rules, function(key, value) { 
    286                 rules[key] = jQuery.validator.normalizeRule(value); 
    287             }); 
    288              
    289             function delegate(event) { 
    290                 var validator = jQuery.data(this[0].form, "validator"); 
    291                 validator.settings["on" + event.type] && validator.settings["on" + event.type].call(validator, this[0] ); 
    292             } 
    293             jQuery(this.currentForm) 
    294                 .delegate("focusin focusout keyup", ":text, :password, :file, select, textarea", delegate) 
    295                 .delegate("click", ":radio, :checkbox", delegate); 
    296         }, 
    297  
    298         // http://docs.jquery.com/Plugins/Validation/Validator/form 
    299         form: function() { 
    300             this.checkForm(); 
    301             jQuery.extend(this.submitted, this.errorMap); 
    302             this.invalid = jQuery.extend({}, this.errorMap); 
    303             if (!this.valid()) 
    304                 jQuery(this.currentForm).triggerHandler("invalid-form.validate", [this]); 
    305             this.showErrors(); 
    306             return this.valid(); 
    307         }, 
    308          
    309         checkForm: function() { 
    310             this.prepareForm(); 
    311             for ( var i = 0, elements = this.elements(); elements[i]; i++ ) { 
    312                 this.check( elements[i] ); 
    313             } 
    314             return this.valid();  
    315         }, 
    316          
    317         // http://docs.jquery.com/Plugins/Validation/Validator/element 
    318         element: function( element ) { 
    319             element = this.clean( element ); 
    320             this.lastElement = element; 
    321             this.prepareElement( element ); 
    322             var result = this.check( element ); 
    323             if ( result ) { 
    324                 delete this.invalid[element.name]; 
    325             } else { 
    326                 this.invalid[element.name] = true; 
    327             } 
    328             if ( !this.numberOfInvalids() ) { 
    329                 // Hide error containers on last error 
    330                 this.toHide.push( this.containers ); 
    331             } 
    332             this.showErrors(); 
    333             return result; 
    334         }, 
    335  
    336         // http://docs.jquery.com/Plugins/Validation/Validator/showErrors 
    337         showErrors: function(errors) { 
    338             if(errors) { 
    339                 // add items to error list and map 
    340                 jQuery.extend( this.errorMap, errors ); 
    341                 this.errorList = []; 
    342                 for ( var name in errors ) { 
    343                     this.errorList.push({ 
    344                         message: errors[name], 
    345                         element: this.findByName(name)[0] 
    346                     }); 
    347                 } 
    348                 // remove items from success list 
    349                 this.successList = jQuery.grep( this.successList, function(element) { 
    350                     return !(element.name in errors); 
    351                 }); 
    352             } 
    353             this.settings.showErrors 
    354                 ? this.settings.showErrors.call( this, this.errorMap, this.errorList ) 
    355                 : this.defaultShowErrors(); 
    356         }, 
    357          
    358         // http://docs.jquery.com/Plugins/Validation/Validator/resetForm 
    359         resetForm: function() { 
    360             if ( jQuery.fn.resetForm ) 
    361                 jQuery( this.currentForm ).resetForm(); 
    362             this.prepareForm(); 
    363             this.hideErrors(); 
    364             this.elements().removeClass( this.settings.errorClass ); 
    365         }, 
    366          
    367         numberOfInvalids: function() { 
    368             return this.objectLength(this.invalid); 
    369         }, 
    370          
    371         objectLength: function( obj ) { 
    372             var count = 0; 
    373             for ( var i in obj ) 
    374                 count++; 
    375             return count; 
    376         }, 
    377          
    378         hideErrors: function() { 
    379             this.addWrapper( this.toHide ).hide(); 
    380         }, 
    381          
    382         valid: function() { 
    383             return this.size() == 0; 
    384         }, 
    385          
    386         size: function() { 
    387             return this.errorList.length; 
    388         }, 
    389          
    390         focusInvalid: function() { 
    391             if( this.settings.focusInvalid ) { 
    392                 try { 
    393                     jQuery(this.findLastActive() || this.errorList.length && this.errorList[0].element || []).filter(":visible").focus(); 
    394                 } catch(e) { /* ignore IE throwing errors when focusing hidden elements */ } 
    395             } 
    396         }, 
    397          
    398         findLastActive: function() { 
    399             var lastActive = this.lastActive; 
    400             return lastActive && jQuery.grep(this.errorList, function(n) { 
    401                 return n.element.name == lastActive.name; 
    402             }).length == 1 && lastActive; 
    403         }, 
    404          
    405         elements: function() { 
    406             var validator = this, 
    407                 rulesCache = {}; 
    408              
    409             // select all valid inputs inside the form (no submit or reset buttons) 
    410             // workaround with jQuery([]).add until http://dev.jquery.com/ticket/2114 is solved 
    411             return jQuery([]).add(this.currentForm.elements) 
    412             .filter("input, select, textarea") 
    413             .not(":submit, :reset, [disabled]") 
    414             .not( this.settings.ignore ) 
    415             .filter(function() { 
    416                 !this.name && validator.settings.debug && window.console && console.error( "%o has no name assigned", this); 
    417              
    418                 // select only the first element for each name, and only those with rules specified 
    419                 if ( this.name in rulesCache || !validator.objectLength($(this).rules()) ) 
    420                     return false; 
    421                  
    422                 rulesCache[this.name] = true; 
    423                 return true; 
    424             }); 
    425         }, 
    426          
    427         clean: function( selector ) { 
    428             return jQuery( selector )[0]; 
    429         }, 
    430          
    431         errors: function() { 
    432             return jQuery( this.settings.errorElement + "." + this.settings.errorClass, this.errorContext ); 
    433         }, 
    434          
    435         reset: function() { 
    436             this.successList = []; 
    437             this.errorList = []; 
    438             this.errorMap = {}; 
    439             this.toShow = jQuery( [] ); 
    440             this.toHide = jQuery( [] ); 
    441             this.formSubmitted = false; 
    442         }, 
    443          
    444         prepareForm: function() { 
    445             this.reset(); 
    446             this.toHide = this.errors().push( this.containers ); 
    447         }, 
    448          
    449         prepareElement: function( element ) { 
    450             this.reset(); 
    451             this.toHide = this.errorsFor(element); 
    452         }, 
    453      
    454         check: function( element ) { 
    455             element = this.clean( element ); 
    456              
    457             // if radio/checkbox, validate first element in group instead 
    458             if (this.checkable(element)) { 
    459                 element = this.findByName( element.name )[0]; 
    460             } 
    461              
    462             var rules = $(element).rules(); 
    463             var dependencyMismatch = false; 
    464             for( method in rules ) { 
    465                 var rule = { method: method, parameters: rules[method] }; 
    466                 try { 
    467                     var result = jQuery.validator.methods[method].call( this, jQuery.trim(element.value), element, rule.parameters ); 
    468                      
    469                     // if a method indicates that the field is optional and therefore valid, 
    470                     // don't mark it as valid when there are no other rules 
    471                     if ( result == "dependency-mismatch" ) { 
    472                         dependencyMismatch = true; 
    473                         continue; 
    474                     } 
    475                     dependencyMismatch = false; 
    476                      
    477                     if ( result == "pending" ) { 
    478                         this.toHide = this.toHide.not( this.errorsFor(element) ); 
    479                         return; 
    480                     } 
    481                      
    482                     if( !result ) { 
    483                         this.formatAndAdd( element, rule ); 
    484                         return false; 
    485                     } 
    486                 } catch(e) { 
    487                     this.settings.debug && window.console && console.log("exception occured when checking element " + element.id 
    488                          + ", check the '" + rule.method + "' method"); 
    489                     throw e; 
    490                 } 
    491             } 
    492             if (dependencyMismatch) 
    493                 return; 
    494             if ( this.objectLength(rules) ) 
    495                 this.successList.push(element); 
    496             return true; 
    497         }, 
    498          
    499         // return the custom message for the given element name and validation method 
    500         customMessage: function( name, method ) { 
    501             var m = this.settings.messages[name]; 
    502             return m && (m.constructor == String 
    503                 ? m 
    504                 : m[method]); 
    505         }, 
    506          
    507         // return the first defined argument, allowing empty strings 
    508         findDefined: function() { 
    509             for(var i = 0; i < arguments.length; i++) { 
    510                 if (arguments[i] !== undefined) 
    511                     return arguments[i]; 
    512             } 
    513             return undefined; 
    514         }, 
    515          
    516         defaultMessage: function( element, method) { 
    517             return this.findDefined( 
    518                 this.customMessage( element.name, method ), 
    519                 // title is never undefined, so handle empty string as undefined 
    520                 element.title || undefined, 
    521                 jQuery.validator.messages[method], 
    522                 "<strong>Warning: No message defined for " + element.name + "</strong>" 
    523             ); 
    524         }, 
    525          
    526         formatAndAdd: function( element, rule ) { 
    527             var message = this.defaultMessage( element, rule.method ); 
    528             if ( typeof message == "function" )  
    529                 message = message.call(this, rule.parameters, element); 
    530             this.errorList.push({ 
    531                 message: message, 
    532                 element: element 
    533             }); 
    534             this.errorMap[element.name] = message; 
    535             this.submitted[element.name] = message; 
    536         }, 
    537          
    538         addWrapper: function(toToggle) { 
    539             if ( this.settings.wrapper ) 
    540                 toToggle.push( toToggle.parents( this.settings.wrapper ) ); 
    541             return toToggle; 
    542         }, 
    543          
    544         defaultShowErrors: function() { 
    545             for ( var i = 0; this.errorList[i]; i++ ) { 
    546                 var error = this.errorList[i]; 
    547                 this.settings.highlight && this.settings.highlight.call( this, error.element, this.settings.errorClass ); 
    548                 this.showLabel( error.element, error.message ); 
    549             } 
    550             if( this.errorList.length ) { 
    551                 this.toShow.push( this.containers ); 
    552             } 
    553             if (this.settings.success) { 
    554                 for ( var i = 0; this.successList[i]; i++ ) { 
    555                     this.showLabel( this.successList[i] ); 
    556                 } 
    557             } 
    558             if (this.settings.unhighlight) { 
    559                 for ( var i = 0, elements = this.validElements(); elements[i]; i++ ) { 
    560                     this.settings.unhighlight.call( this, elements[i], this.settings.errorClass ); 
    561                 } 
    562             } 
    563             this.toHide = this.toHide.not( this.toShow ); 
    564             this.hideErrors(); 
    565             this.addWrapper( this.toShow ).show(); 
    566         }, 
    567          
    568         validElements: function() { 
    569             return this.elements().not(this.invalidElements()); 
    570         }, 
    571          
    572         invalidElements: function() { 
    573             return jQuery(this.errorList).map(function() { 
    574                 return this.element; 
    575             }); 
    576         }, 
    577          
    578         showLabel: function(element, message) { 
    579             var label = this.errorsFor( element ); 
    580             if ( label.length ) { 
    581                 // refresh error/success class 
    582                 label.removeClass().addClass( this.settings.errorClass ); 
    583              
    584                 // check if we have a generated label, replace the message then 
    585                 label.attr("generated") && label.html(message); 
    586             } else { 
    587                 // create label 
    588                 label = jQuery("<" + this.settings.errorElement + "/>") 
    589                     .attr({"for":  this.idOrName(element), generated: true}) 
    590                     .addClass(this.settings.errorClass) 
    591                     .html(message || ""); 
    592                 if ( this.settings.wrapper ) { 
    593                     // make sure the element is visible, even in IE 
    594                     // actually showing the wrapped element is handled elsewhere 
    595                     label = label.hide().show().wrap("<" + this.settings.wrapper + ">").parent(); 
    596                 } 
    597                 if ( !this.labelContainer.append(label).length ) 
    598                     this.settings.errorPlacement 
    599                         ? this.settings.errorPlacement(label, jQuery(element) ) 
    600                         : label.insertAfter(element); 
    601             } 
    602             if ( !message && this.settings.success ) { 
    603