jQuery: The Write Less, Do More JavaScript Library

Changeset 5561

Show
Ignore:
Timestamp:
05/12/08 11:04:58 (2 months ago)
Author:
joern.zaefferer
Message:

validation: Fixed #2215: Fixed message display to call unhighlight as part of showing and hiding messages, no more visual side-effects while checking an element and extracted validator.checkForm to validate a form without UI sideeffects

Location:
trunk/plugins/validate
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/plugins/validate/changelog.txt

    r5559 r5561  
    1313* Fixed creditcard validation to accept only digits and dashes ("asdf" is not a valid creditcard number) 
    1414* Allow both button and input elements for cancel buttons (via class="cancel") 
     15* Fixed #2215: Fixed message display to call unhighlight as part of showing and hiding messages, no more visual side-effects while checking an element and extracted validator.checkForm to validate a form without UI sideeffects 
    1516 
    16171.2.1 
  • trunk/plugins/validate/jquery.validate.js

    r5560 r5561  
    297297        // http://docs.jquery.com/Plugins/Validation/Validator/form 
    298298        form: function() { 
    299             this.prepareForm(); 
    300             var elements = this.elements(); 
    301             for ( var i = 0; elements[i]; i++ ) { 
    302                 this.check( elements[i] ); 
    303             } 
     299            this.checkForm(); 
    304300            jQuery.extend(this.submitted, this.errorMap); 
    305301            this.invalid = jQuery.extend({}, this.errorMap); 
     
    308304            this.showErrors(); 
    309305            return this.valid(); 
     306        }, 
     307         
     308        checkForm: function() { 
     309            this.prepareForm(); 
     310            for ( var i = 0, elements = this.elements(); elements[i]; i++ ) { 
     311                this.check( elements[i] ); 
     312            } 
     313            return this.valid();  
    310314        }, 
    311315         
     
    449453        check: function( element ) { 
    450454            element = this.clean( element ); 
    451             this.settings.unhighlight && this.settings.unhighlight.call( this, element, this.settings.errorClass ); 
    452455             
    453456            // if radio/checkbox, validate first element in group instead 
     
    552555                } 
    553556            } 
     557            if (this.settings.unhighlight) { 
     558                for ( var i = 0, elements = this.validElements(); elements[i]; i++ ) { 
     559                    this.settings.unhighlight.call( this, elements[i], this.settings.errorClass ); 
     560                } 
     561            } 
    554562            this.toHide = this.toHide.not( this.toShow ); 
    555563            this.hideErrors(); 
    556564            this.addWrapper( this.toShow ).show(); 
     565        }, 
     566         
     567        validElements: function() { 
     568            return this.elements().not(this.invalidElements()); 
     569        }, 
     570         
     571        invalidElements: function() { 
     572            return jQuery(this.errorList).map(function() { 
     573                return this.element; 
     574            }); 
    557575        }, 
    558576         
  • trunk/plugins/validate/test/test.js

    r5251 r5561  
    298298 
    299299test("option: (un)highlight, custom", function() { 
    300     expect(6); 
    301     $("#testForm1").validate({ 
     300    expect(5); 
     301    $("#testForm1clean").validate({ 
    302302        highlight: function(element, errorClass) { 
    303303            equals( "invalid", errorClass ); 
     
    308308            $(element).show(); 
    309309        }, 
    310         errorClass: "invalid" 
    311     }); 
    312     var e = $("#firstname") 
     310        errorClass: "invalid", 
     311        rules: { 
     312            firstname: "required" 
     313        } 
     314    }); 
     315    var e = $("#firstnamec") 
    313316    ok( e.is(":visible") ); 
    314317    e.valid()