Hi Kazuya,

 

As Matt said – in Flex 1.5, validators don’t support binding.

 

Below is a workaround for your issue. 

 

I got most of the code from here:

http://blog.daemon.com.au/archives/000317.html

 

 

Main.mxml

*************

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" xmlns:local="*">

                <mx:Script>

                <![CDATA[

                                function testField( validator, value ){

                                                validator.numLength = name1.maxChars;

                                                //debug

//mx.core.Application.alert(validator.numLength);

                                                validator.doValidation(value);

                }

                ]]>

                </mx:Script>

               

                <mx:Model id="test">

                                <firstField>{name1.text}</firstField>

                                <secondField>{name2.text}</secondField>

                </mx:Model>

               

                <local:RequiredFieldValidator xmlns="*" field="test.secondField" validate="testField(event.validator, event.value)"/>

               

                <mx:Form>

                                <mx:FormItem>

                                                <mx:TextInput id="name1" maxChars="5"/>

                                </mx:FormItem>

                                <mx:FormItem>

                                                <mx:TextInput id="name2"/>

                                </mx:FormItem>

                </mx:Form>

</mx:Application>

 

 

RequiredFieldValidator.as

********************************

class RequiredFieldValidator extends mx.validators.Validator {

    public var numLength:Number;

               

                public function RequiredFieldValidator(){

               

                }

                public function doValidation(fieldString) : Void{

                                RequiredFieldValidator.validateValue(this, fieldString, null, numLength);

                }

                public static function validateValue(validator:mx.validators.Validator, fieldString:String, subField, numLength) : Boolean{

                                var tempValue = new String(fieldString);

                               

                                if(tempValue.length > numLength){

                                                validator.validationError("TooLong", "You entered " + tempValue.length + " characters. The limit is " + numLength, subField);

                                                return false;

                                }

                                return true;

                }

}

 

 

regards,

peter

 

 


From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of KOMON Kazuya
Sent: Wednesday, February 22, 2006 1:40 AM
To: [email protected]
Subject: Re: [flexcoders] Validatior's binding problem?

 

Hi, Matt

Thank you for your reply.

I watched the source which generated, it became "undefined" in case of binding.
That was a reason.

Thank you,
KAZUYA KOMON

-----Original Message-----
Sorry, Validators in 1.5 can't accept binding, they're special
components.  We changed that in 2.0. 

Matt

-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of KAZUYA KOMON
Sent: Monday, February 20, 2006 12:05 AM
To: [email protected]
Subject: [flexcoders] Validatior's binding problem?

Hi, all


I'm trying to bind attribute from MXML file to custom validator.
(using 1.5)


// Code(MXML) :
<RequiredFieldValidator xmlns="*" field="formData.text"
    numLength="{name.maxChars}"/>
    ^^^^^^^^^
<mx:TextInput id="name" width="200" maxChars="5" />


// Code(ActionScript - RequiredFieldValidator.as) :
class RequiredFieldValidator extends mx.validators.Validator {
    var numLength:Number;
        ^^^^^^^^^
    ...
}


If I set number directory (ex. numLength="5") , I can.
But if I use binding, I can't.
Is there something a good idea?

Any help is greatly appreciate.


Thanks,
KAZUYA KOMON


--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives:
http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links



--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




Reply via email to