basevalidator.lzx

<!--
********************************************************
* [[validators/basevalidator]]
* 2005/12/21 ver.2.0.0
* 2005/11/06 ver.1.0.
* togawa manabu
* web:http://laszlo.jp
* mail:webmaster@laszlo.jp 
********************************************************
-->
<!---
      @topic Incubator
      @subtopic Validators
  -->
<library>
    <resource name="rsc_ok" src="resources/ok.gif"/>
    <resource name="rsc_error" src="resources/error.gif"/>

    <class name="basevalidator">
        <attribute name="isformvalidator" type="boolean" value="true"/>
        <attribute name="errorstring" type="string" value=""/>
        <attribute name="required" type="boolean" value="false"/>
        <attribute name="requiredErrorstring" type="string" value="this field is required."/>
        <attribute name="innercompornent" type="expression" value="null"/>
        <attribute name="iserror" type="boolean" value="false"/>
        <attribute name="trim" type="boolean" value="true"/>
        
        <method name="addSubview" args="item">
            super.addSubview(item);
            if(item instanceof lz.edittext) {
                new lz.Delegate(this, "doValidation", item, "onkeyup");
                new lz.Delegate(this, "doValidation", item, "ontext");
                this.innercompornent = item;
            }
        </method>

        <method name="getValueText" args="val">
            
            var valtext = this.innercompornent.text;
            if(trim && val == null){
                valtext = this.dotrim(valtext);
                this.innercompornent.setAttribute('text', valtext);
            }

            return valtext;
            
        </method>

        <!-- this trim method from bfagan. Thanks a lot!. -->
        <method name="dotrim" args="s">
        
            var aEntry = s.split(' ');
            
            var tEntry = new Array();
            for (var n = 0; n < aEntry.length; n++) {
                if (aEntry[n] != '') {
                    tEntry.push(aEntry[n]);
                }
            }
                                    
            return tEntry.join(" ");
        
        </method>
        
        <method name="setErrorstring" args="message">
            this.errorstring = message;
            setErrorMessage();
        </method>
        <method name="getErrorstring">
            return parent.errorstring;
        </method>
        
        <method name="setErrorMessage">
            if(this.errorstring == ""){
                messagetext.setAttribute('text', "");
                icon.setok();
                this.setAttribute("iserror", false);
            }else{
                messagetext.setAttribute('text', this.errorstring);
                icon.seterror();
                this.setAttribute("iserror", true);
            }
            this.rv.update();
        </method>

        <method name="cleanErrors">
            messagetext.setAttribute('text', "");
            icon.clear();
        </method>

        <reverselayout name="rv" axis="x"/>

        <text name="messagetext" fgcolor="red" resize="true"/>

        <view name="icon" width="18" height="16">
            <view name="ok" resource="rsc_ok" visible="false" width="10" height="10"/>
            <view name="error" resource="rsc_error" visible="false" width="10" height="10"/>
            <method name="setok">
                this.ok.setAttribute('visible', true);
                this.error.setAttribute('visible', false);
            </method>
            <method name="seterror">
                this.ok.setAttribute('visible', false);
                this.error.setAttribute('visible', true);
            </method>
            <method name="clear">
                this.ok.setAttribute('visible', false);
                this.error.setAttribute('visible', false);
            </method>
        </view>
        
    </class>
</library>
<!-- * X_LZ_COPYRIGHT_BEGIN ***************************************************
* Copyright 2007, 2009,2011 Laszlo Systems, Inc. All Rights Reserved.                    *
* Use is subject to license terms.                                            *
* X_LZ_COPYRIGHT_END ****************************************************** -->
<!-- @LZX_VERSION@                                                         -->

Cross References

Resources

Name Source Image
rsc_ok resources/ok.gif
rsc_error resources/error.gif

Classes