8 Replies Latest reply on Apr 22, 2006 6:04 AM by Digital_Hand

    Simple Question about Validator

    Digital_Hand
      Hi all,

      After the validating for the form's inputs is done where I should place my code that will send inputs value to a particular java method through RemoteObject?

      Flex v1.5
        • 1. Simple Question about Validator
          Digital_Hand Level 1
          For the following example:
          Note : [ Assume that Model and Validator are defined probably ]

          <mx:Button label="Send" click="mx.validators.Validator.isValid( this, 'settingsModel' ); " />

          If I want to send to inputs as parameters then I have to modify the above to be like this

          <mx:Button label="Send" click="mx.validators.Validator.isValid( this, 'settingsModel' ); add(input1.Text,input2.Text)" />

          Flex will validate the inputs then it will send them to add method, Is that right ???
          • 2. Re: Simple Question about Validator
            ntsiii Level 3
            I've not worked with validators, but the code looks ok.

            Tracy
            • 3. Re: Simple Question about Validator
              Digital_Hand Level 1
              It works, thanks for your reply.

              The last question here, can I play with <mx:Model> content programmatically ??? and how ???
              • 4. Re: Simple Question about Validator
                ntsiii Level 3
                Give your Model an id: <mx:Model id="myModel" ...

                Then do something like:
                var sFirstName:String = myModel.employees[0].firstname;

                Tracy
                • 5. Re: Simple Question about Validator
                  Digital_Hand Level 1
                  seem fine but it doesnot work with me, here is my code

                  I want to change the structure of Model programmatically, so in particular moment or " once I disable some components " I do not want from the Validator to keep the checking for those component value.

                  In the example here, I have tried to change the structure of CheckModel. First time, Validator will check username and password, Then I have tried to force the validator to check password and link only. But its fail.

                  <?xml version="1.0" encoding="utf-8"?>
                  <mx:Application xmlns:mx=" http://www.macromedia.com/2003/mxml">
                  <mx:Script>
                  <![CDATA[
                  import mx.controls.Alert;

                  function changeModel():Void
                  {
                  usernameFormItem.required = false;
                  CheckModel.USERNAME[0].firstname = link.text;
                  }

                  function checkValidity(event):Void
                  {
                  var temp;
                  temp= mx.validators.Validator.isStructureValid(this,'CheckModel');
                  if(temp == true)
                  {
                  changeModel();
                  }
                  }

                  ]]>
                  </mx:Script>

                  <mx bject id="CheckModel" />

                  <mx:StringValidator field="CheckModel.USERNAME" minLength="4" maxLength="12"/>
                  <mx:StringValidator field="CheckModel.PASSWORD" minLength="4" maxLength="12"/>

                  <mx anel title="Login" width="400" height="200" marginBottom="20" marginLeft="20" marginRight="20" marginTop="20">
                  <mx:Form>
                  <mx:FormItem id="usernameFormItem" label="user name :" required="true">
                  <mx:TextInput id="username" />
                  </mx:FormItem>
                  <mx:FormItem label="password :" required="true">
                  <mx:TextInput id="password" />
                  </mx:FormItem>
                  <mx:FormItem label="link :" required="true">
                  <mx:TextInput id="link" />
                  </mx:FormItem>
                  </mx:Form>
                  <mx:ControlBar horizontalAlign="right">
                  <mx:HBox><mx:Button id="okButton" label="OK" click="checkValidity();" /><mx:Button id="cancelButton" label="Cancel" /></mx:HBox>
                  </mx:ControlBar>
                  </mx anel>


                  </mx:Application>
                  • 6. Re: Simple Question about Validator
                    Digital_Hand Level 1
                    Is there any way to do what I want exactly?

                    Disable a particular TextInput and remove its state to be check by StringValidator.



                    • 7. Re: Simple Question about Validator
                      Digital_Hand Level 1
                      Please, any help would be appreciated
                      • 8. Simple Question about Validator
                        Digital_Hand Level 1
                        Hi all,

                        I have found a way to do that. Just by using

                        mx.validators.Validator.disable & mx.validators.Validator.enable

                        Now I can say I have finished the half of my application. But, still need to know how to prevent some characters like @, !, $, ?

                        Thanks in advance

                        -------------------------

                        I think I can do it by the customized validator