3 Replies Latest reply on Oct 17, 2006 10:10 AM by rob_o

    Validate multi-level model bug?

    rob_o
      Hey guys, the property field of the validators say that it accepts a dot-delimited String. However, it doesn't work.

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

      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">

      <mx:Model id="User">
      <User>
      <Email>{email.text}</Email>
      <Billing>
      <FirstName>{bill_fname.text}</FirstName>
      </Billing>
      </User>
      </mx:Model>

      <mx:Panel title="Order Info"
      paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">

      <mx:Form width="100%" height="100%">

      <mx:FormItem label="E-mail address">
      <mx:TextInput id="email" width="200"/>
      </mx:FormItem>

      <mx:FormItem label="First name">
      <mx:TextInput id="bill_fname" width="200"/>
      </mx:FormItem>

      </mx:Form>
      </mx:Panel>

      <mx:EmailValidator source="{User}" property="Email"
      trigger="{email}" listener="{email}"/>

      <mx:StringValidator source="{User}" property="Billing.FirstName"
      minLength="4" maxLength="12" trigger="{bill_fname}" listener="{bill_fname}"/>


      </mx:Application>

      Email works fine, but Billing.FirstName does not. If i put it on the same level as Email, say Bill_FirstName, then it works and gives a message like "Too short..." instead of always saying "required."

      Is this a bug? Or is there just a little more that I'm missing?

      Thanks all.
        • 1. Re: Validate multi-level model bug?
          rob_o Level 1
          i just tried adding this section and it didn't work.

          <mx:Script>
          <![CDATA[
          [Bindable]
          public var bill_mod:String = "Billing.FirstName";
          ]]>
          </mx:Script>


          <mx:StringValidator source="{User}" property="{bill_mod}"
          minLength="4" maxLength="12" trigger="{bill_fname}" listener="{bill_fname}"/>
          • 2. Re: Validate multi-level model bug?
            rob_o Level 1
            Could someone load up the simple app and try it out please?

            I tried replacing the validator mxml with this:

            <mx:Script>
            <![CDATA[
            import mx.validators.StringValidator;

            private var nameValidator:StringValidator;
            private function createHandler():void {
            nameValidator = new StringValidator();
            nameValidator.source = User;
            nameValidator.property = "Billing.FirstName";
            nameValidator.minLength = 4;
            nameValidator.minLength = 12;
            nameValidator.trigger = bill_fname;
            nameValidator.listener = bill_fname;
            }

            ]]>
            </mx:Script>

            and:
            creationComplete="createHandler()"

            in the app tag, and that didn't fix it either...
            • 3. Re: Validate multi-level model bug?
              rob_o Level 1
              Hey guys, I posted a comment on the livedocs and Stephen nicely replied with a solution to the problem:

              http://livedocs.macromedia.com/flex/2/docs/00001051.html

              Sorry for the mistake. The documentation on Validator.source and Validator.property was incorrect. The 'source' property takes a dot-delimited path, and the 'property' property takes an element name. So, if you have a Model that looks like this:

              <mx:Model id="reg">
              <registration>
              <name>
              <last></last>
              <first></first>
              </name>;
              <email>{email.text}</email>
              <phone>{phone.text}</phone>
              <zip>{zip.text}</zip>
              <ssn>{ssn.text}</ssn>
              </registration>
              </mx:Model>

              Set 'source' to "reg.name" and 'property' to "last".

              Stephen Gilson
              Flex Doc Team