zoukankan      html  css  js  c++  java
  • flex>自定义验证组件 小强斋

    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>



     

  • 相关阅读:
    linux shell获取用户输入
    yii2 笔记(1)
    yii2 数据库查询
    Yii2 环境配置生产环境和测试环境
    mysql 中find_in_set()和in()用法比较
    使用js提交form表单的两种方法
    base64编码的原理及实现
    浅析HTTP/2的多路复用
    Nginx 所使用的 epoll 模型是什么?
    git代码统计
  • 原文地址:https://www.cnblogs.com/xiaoqiangzhaitai/p/5637724.html
Copyright © 2011-2022 走看看