关闭

flex---->自定义验证组件

398人阅读 评论(0) 收藏 举报

myValidators.as

package myCompenent
{
 import mx.validators.ValidationResult;
 import mx.validators.Validator;
 public class myValidators extends Validator
 {
  public function myValidators()
  {
   super();
  }
  
  private var results:Array;
  //重写验证函数
  override protected function doValidation(value:Object):Array
  {
   var s:String= value as String;
   results=[];
   results=super.doValidation(value);
   if(results.length>0)
    return results;
   if(s.length>6)
   {
    results.push(new ValidationResult(true,"text","StringTooLong","字符长度超过6了"));
   }
   return results;
  }
 }
}

main.mxml

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
 xmlns:s="library://ns.adobe.com/flex/spark" 
 xmlns:mx="library://ns.adobe.com/flex/halo" 
 minWidth="1024" minHeight="768" xmlns:myCompenent="myCompenent.*">
 
 <fx:Declarations>
  <myCompenent:myValidators id="mycom" source="{textinput}" property="text"/>  
 </fx:Declarations>
 <s:Panel x="131" y="54" width="405" height="200" title="自定义验证组件">
  <s:TextInput x="133" y="25" id="textinput"/>
  <s:Label x="133" y="55"  width="128" height="29" text="{textinput.errorString}" />
  <s:Button x="133" y="92" label="验证" id="btn" click="mycom.validate();"/>  
 </s:Panel>
</s:Application>



 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:323285次
    • 积分:2657
    • 等级:
    • 排名:第14212名
    • 原创:104篇
    • 转载:212篇
    • 译文:0篇
    • 评论:17条