zoukankan      html  css  js  c++  java
  • flex3 自定义控件

    用于验证两个日期的大小。
    在Flex3 中自定义控件需要重写 override protected function doValidation(value:Object):Array 方法
    /**
     * @author 		
     * @date 		2010-07-01
     * @description	日期比较验证
     */
    package com.xxxx.szecp.components.validator
    {
    	import com.founder.szecp.common.FounderUtils;
    	
    	import mx.controls.DateField;
    	import mx.validators.ValidationResult;
    	import mx.validators.Validator;
    
    	public class DateCompareValidate extends Validator
    	{
    		private var resultsError:Array;			//错误数组
    		private const errorStr : String = "结束日期必需大于开始日期!";
    		private var _target:Object; //目标
    		private var _targetProperty:String; //目标值
    
    		[Inspectable(category="General")]
    		public function get target():Object
    		{
    			return _target;
    		}
    
    		public function set target(value:Object):void
    		{
    			if (_target == value)
    				return;
    
    			if (value is String)
    			{
    				var message:String=resourceManager.getString("validators", "SAttribute", [value]);
    				throw new Error(message);
    			}
    			_target=value;
    		}
    
    
    
    		[Inspectable(category="General")]
    		public function get targetProperty():String
    		{
    			return _targetProperty;
    		}
    
    		public function set targetProperty(value:String):void
    		{
    			_targetProperty=value;
    		}
    
    		public function DateCompareValidate()
    		{
    			super();
    		}
    
    		override protected function doValidation(value:Object):Array
    		{
    			resultsError = [];
    			resultsError=super.doValidation(value);
    			dateValidation();
    			return resultsError;
    		}
    
    		private function dateValidation():void
    		{
    			var i : int = compare(convertToStringDate(getValueFromSource().toString()),convertToStringDate(getValueFromTarget().toString()));
    			if (i<0)
    			{
    				resultsError.push(new ValidationResult(true,"text","DateError",errorStr));
    			}
    		}
    
    		protected function getValueFromTarget():Object
    		{
    			var message:String;
    
    			if (_target && _targetProperty)
    			{
    				return _target[_targetProperty];
    			}
    
    			else if (!_target && _targetProperty)
    			{
    				message=resourceManager.getString("validators", "SAttributeMissing");
    				throw new Error(message);
    			}
    
    			else if (_target && !_targetProperty)
    			{
    				message=resourceManager.getString("validators", "PAttributeMissing");
    				throw new Error(message);
    			}
    
    			return null;
    		}
    		
    		/**
    		 * 比较两个日期大小
    		 */
    		private function compare(date1:Date, date2:Date):int
    		{
    			if (Number(date1) < Number(date2))
    			{
    				return -1
    			}
    			if (Number(date1) == Number(date2))
    			{
    				return 0;
    			}
    			return 1;
    		}
    		
    		private function convertToStringDate(str : String) : Date
    		{
    			return DateField.stringToDate(str,"YYYY-MM-DD");
    		}
    	}
    }
    
  • 相关阅读:
    ASP.NET MVC and jqGrid 学习笔记 5-添加数据
    Python学习笔记 第一课 列表
    Python学习笔记
    ASP.NET MVC and jqGrid 学习笔记 4-排序
    ASP.NET MVC and jqGrid 学习笔记 3-如何从数据库获得数据
    JS高级程序设计第三版——基本概念
    任务八:响应式网格(栅格化)布局
    任务七:实现常见的技术产品官网的页面结构及样式布局
    JSON Schema(模式)
    jquery选择器(转)
  • 原文地址:https://www.cnblogs.com/warrior/p/1769966.html
Copyright © 2011-2022 走看看