flex Validators
package com.wks.util ????if ( requiredNum == 0 ){ ?????_required = false; ?????_valid = true; ????} ???} ??} ?? ??/** ?? * 验证触发器 ?? */ ??private var _trigger:IEventDispatcher; ??public function get trigger():IEventDispatcher{ ???return _trigger; ??} ??public function set trigger(value:IEventDispatcher):void{ ???_trigger = value; ???if ( validatorArray ){ ????for each( var validator:Validator in validatorArray ){ ?????validator.trigger = _trigger; ????} ???} ??} ?? ??/** ?? * 验证触发事件类型 ?? */ ??private var _triggerEvent:String = FlexEvent.VALUE_COMMIT; ??public function get triggerEvent():String{ ???return _triggerEvent; ??} ??public function set triggerEvent(value:String):void{ ???_triggerEvent = value; ???if ( validatorArray ){ ????for each( var validator:Validator in validatorArray ){ ?????validator.triggerEvent = _triggerEvent; ????} ???} ??} ?? ??/** ?? * 构造函数 ?? * @param target ?? * @return ?? */ ??public function Validators(target:IEventDispatcher=null) ??{ ???super(target); ??} ?? ??/** ?? * 实现IMXMLObject ?? * @param document ?? * @param id ?? * @return ?? */ ??public function initialized(document:Object,id:String):void ??{ ???this.id = id; ???this.document = document; ??} ?? ??/** ?? * 验证器验证结果事件侦听处理函数 ?? * @param event 验证结果事件信息 ?? * @return ?? */ ??protected function resultHandler(event:ValidationResultEvent):void{ ???//更新框架验证结果数组 ???var alreadyIn:Boolean; ???if ( this.results == null ) { ????results = new Array(); ???} ??? ???for ( var i:int = 0; i < results.length; i++ ){ ????if ( results[i].currentTarget == event.currentTarget ){ ?????results[i] = event; ?????alreadyIn = true; ????} ???} ??? ???if ( !alreadyIn ){ ????results.push(event); ???} ??? ???//强制验证的验证器都验证过之后可以计算总体结果 ???if ( requiredValidatedNum == requiredNum ){ ????var wholeValid:Boolean = true; ????for ( var j:int = 0; j < results.length; j++ ){ ?????var isValid:Boolean = results[j].type == ValidationResultEvent.VALID; ?????wholeValid = wholeValid && isValid; ????} ????if ( valid != wholeValid ){ ?????this._valid = wholeValid; ?????dispatchEvent(new Event(VALID_CHANGEED_EVENT)); ????} ????if ( valid ){ ?????dispatchEvent(new ValidationResultEvent(ValidationResultEvent.VALID)); ????} else { ?????dispatchEvent(new ValidationResultEvent(ValidationResultEvent.INVALID)); ????} ???} else { ????if ( valid ){ ?????_valid = !valid; ?????dispatchEvent(new Event(VALID_CHANGEED_EVENT)); ????} ???} ??} ?? ??/** ?? * 清空错误信息 ?? * @return ?? */ ??public function clearErrorMessages():void{ ???if ( results ){ ????for each( var vre:ValidationResultEvent in results ){ ?????if ( vre.type == ValidationResultEvent.INVALID ){ ??????if ( vre.currentTarget is Validator ){ ???????vre.results = null; ???????if ( vre.currentTarget.listener ){ ????????vre.currentTarget.listener.errorString = null ???????} else if ( vre.currentTarget.source ){ ????????vre.currentTarget.source.errorString = null; ???????} ??????} else if ( vre.currentTarget is Validators ){ ???????(vre.currentTarget as Validators).clearErrorMessages(); ??????} ?????} ????} ???} ??} ?? ??/** ?? * 校验所有的验证器 ?? * @return ?? */ ??public function validate():void{ ???if ( validatorArray ){ ????for each( var validator:Validator in validatorArray ){ ?????validator.validate(); ????} ???} ??} ?} } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |