Changeset 2464

Show
Ignore:
Timestamp:
05/27/2008 10:47:17 AM (5 months ago)
Author:
mikl
Message:

Added Prado.Validation.validateControl(id) on client side

Location:
trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/HISTORY

    r2463 r2464  
    66BUG: Ticket#843 - TDataList alternatinItem issue after changes in rev 2227 (Christophe) 
    77BUG: Ticket#849 - TDatePicker selecting current date problem (Christophe) 
     8ENH: Added Prado.Validation.validateControl(id) on client side to validate a specific control (Michael) 
    89 
    910Version 3.1.2 April 21, 2008 
  • trunk/framework/Web/Javascripts/source/prado/validator/validation3.js

    r2458 r2464  
    7272 * <tt>groupID</tt> if present will only validate the validators 
    7373 * in a particular group.</p> 
     74 * <p>Use <code>{@link Prado.Validation.validateControl}(controlClientID)</code> 
     75 * to trigger validation for a single control.</p> 
    7476 *  
    7577 * @object {static} Prado.Validation 
     
    106108                } 
    107109        }, 
     110 
     111        /** 
     112         * Validate all validators of a specific control. 
     113         * @function {boolean} ? 
     114         * @param {string} id - ID of DOM element to validate  
     115         * @return true if all validators are valid or no validators present, false otherwise. 
     116         */ 
     117    validateControl : function(id)  
     118    { 
     119        var formId=this.getForm(); 
     120 
     121                if (this.managers[formId]) 
     122        { 
     123            return this.managers[formId].validateControl(id); 
     124        } else { 
     125                        throw new Error("A validation manager needs to be created first."); 
     126        } 
     127    }, 
    108128 
    109129        /** 
     
    209229Prado.ValidationManager.prototype = 
    210230{ 
     231        /** 
     232         * Hash of registered validators by control's clientID 
     233         * @var controls 
     234         */ 
     235    controls: {}, 
     236 
    211237        /** 
    212238         * Initialize ValidationManager. 
     
    285311 
    286312        /** 
     313         * Perform validation for all validators of a single control. 
     314         * @function {boolean} ? 
     315         * @param {string} id - ID of DOM element to validate  
     316         * @return true if all validators are valid or no validators present, false otherwise. 
     317         */ 
     318    validateControl : function (id)  
     319    { 
     320        return this.controls[id] ? this.controls[id].invoke('validate',null).all() : true; 
     321    }, 
     322 
     323        /** 
    287324         * Focus on the first validator that is invalid and options.FocusOnError is true. 
    288325         * @function ? 
     
    372409        addValidator : function(validator) 
    373410        { 
    374                 // Erase any existing validator with same options 
    375                 this.validators = this.validators.reject(function(v) 
    376                 { 
    377                         return (v.options.ID==validator.options.ID); 
    378                 }); 
     411                // Remove previously registered validator with same ID 
     412        // to prevent stale validators created by AJAX updates 
     413        this.removeValidator(validator); 
     414 
    379415                this.validators.push(validator); 
    380416                if(validator.group && !this.groups.include(validator.group)) 
    381417                        this.groups.push(validator.group); 
     418 
     419        if (typeof this.controls[validator.control.id] === 'undefined') 
     420            this.controls[validator.control.id] = Array(); 
     421        this.controls[validator.control.id].push(validator); 
    382422        }, 
    383423 
     
    391431                this.summaries.push(summary); 
    392432        }, 
     433 
     434        /** 
     435         * Remove a validator from this manager 
     436         * @function ? 
     437         * @param {TBaseValidator} validator - Validator object 
     438         */ 
     439    removeValidator : function(validator) 
     440    { 
     441                this.validators = this.validators.reject(function(v) 
     442                { 
     443                        return (v.options.ID==validator.options.ID); 
     444                }); 
     445        if (this.controls[validator.control.id]) 
     446            this.controls[validator.control.id].reject( function(v) 
     447            { 
     448                return (v.options.ID==validator.options.ID) 
     449            }); 
     450    }, 
    393451 
    394452        /** 
     
    474532        { 
    475533                /** 
    476                  * ValidationManager options 
     534                 * Validator options 
    477535                 * @var {object} options  
    478536                 */ 
     
    706764         * @constructor {protected} ? 
    707765         * @param {object} options - Options for initialization. 
    708          * @... {string} ID - ID of validation summary element. 
     766         * @... {string} ID - ID of validator 
    709767         * @... {string} FormID - ID of form of this manager. 
    710768         * @... {string} ControlToValidate - ID of control to validate.