Title: New to Flex and having difficulties with validation

OK, so this is not trivial right off the bat right now but it can be done.  Unfortunately I don’t have time to come up with an example that I can code quickly.  Basically you need to have your elements repeated and then capture the change event of the component that is editing the field and trigger validation.  Sound complex?  It canbe J  One thing you could do is encapsulate the validation logic in your visual component itself, something like this:

 

MyTextInput.mxml

<mx:TextInput xmlns:mx=http://www.macromedia.com/2003/mxml>

  <mx:String id=”value”>{text}</mx:String>

  <mx:StringValidator field=”value” minLength=”5” /> <!—this validator is how you would fill in all of the validation logic à

 

  <mx:Script>

    Import mx.validators.Validator;

    function isValid() : Boolean

    {

      return Validator.isValid(this, “value”);

    }

 

</mx:TextInput>

 

 

MyApplication.mxml

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

 

  <mx:Script>

    function areAllValid() : Boolean

    {

      var allValid : Boolean = true;

      for (var i = 0; i < edgeinput.length && allValid; ++i)

      {

        allValid = edgeinput[i].isValid();

      }

      return allValid;

    }

  </mx:Script>

<mx:Model id="edgesmodel" source="edges.xml"/>

<mx:Form>
        <mx:Repeater id="edgesrepeater" dataProvider="{edgesmodel.edge}" recycleChildren="true">                             

                <mx:FormItem label="{edgesrepeater.currentItem.label} : " required="true">
                        <MyTextInput id="edgeinput" width="75" text="{edgesrepeater.currentItem.value}" />
                      </mx:FormItem>                           
        </mx:Repeater>
</mx:Form>

</mx:Application>

 

So that’s how you could determine that everything is valid.  You could also add in additional logic for change detection, etc.

 

Hope this can get you started,

 

Matt


From: Jeroen De Vos [mailto:[EMAIL PROTECTED]
Sent: Friday, March 04, 200512:20 AM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] New to Flex and having difficulties with validation

 

Hi Matt,

 

I want the values of the edgesmodel, that could have been modified, validated, and offcourse turn the borders of the textinput red when they don't validate.

 

Thanks,

Jeroen.

 


Van: Matt Chotin [mailto:[EMAIL PROTECTED]
Verzonden: vrijdag 4 maart 2005 5:57
Aan: flexcoders@yahoogroups.com
Onderwerp: RE: [flexcoders] New to Flex and having difficulties with validation

You want each individual field validated the same way or are you trying to validate the edgesmodel as a whole?  Validators don’t really work well with repeated elements.  You can use some of the static utility methods to set something up, but then havingit turn the borders of the textinputs red gets more difficult.

 

Matt

 


From: Jeroen De Vos [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 03, 2005 6:59 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] New toFlex and having difficulties with validation

 

Hello everyone,

I'm new to Flex (started on Monday) and I'm having a lot of difficulties with validation.
Here's the situation:
I have a model in which I load data from an external XML
<mx:Model id="edgesmodel" source="edges.xml"/>

Then I use a repeater to put the information on screen:
<mx:Form>
        <mx:Repeater id="edgesrepeater" dataProvider="{edgesmodel.edge}" recycleChildren="true">                             

                <mx:FormItem label="{edgesrepeater.currentItem.label} : " required="true">
                        <mx:TextInput id="edgeinput" width="75" text="{edgesrepeater.currentItem.value}" />
                      </mx:FormItem>                           
        </mx:Repeater>
</mx:Form>

The user can change the edge value in the textinput field, so I wrote a function which updates the information in the model (this works fine).

And finally I would like to do validation on the value field of the edgesmodel before I execute the program.
Could someone point out how I can do this validation?

Thanks a lot!
Jeroen.

 

________________________________

Jeroen De Vos
Gemeentelijk Havenbedrijf Antwerpen
C/ICT - AMARIS
________________________________

 

 



Reply via email to