5 Replies Latest reply on May 11, 2009 4:42 AM by Barna Biro

    How to I validate a list selection

    JMCarrenoCanas

      Hi

       

      I`m trying to validate a min selection on a list using the numberValidator, set the source to the id of the list and the property to the selectedIndex of the list.

       

      But when i run the application flex doesn`t validate the selectedIndex, it give me an error of invalidFormatChar.

       

      Any ideas?

       

      Thanks anyway

        • 1. Re: How to I validate a list selection
          Michael Borbor Level 4

          Could you post the code that creates the List and also how you handle 

          the validation.

           

          Sincerely,

           

          Michael

           

          El 11/05/2009, a las 5:29, JMCarrenoCanas <forums@adobe.com> escribió:

           

          >

          Hi

          >

          I`m trying to validate a min selection on a list using the 

          numberValidator, set the source to the id of the list and the 

          property to the selectedIndex of the list.

          >

          But when i run the application flex doesn`t validate the 

          selectedIndex, it give me an error of invalidFormatChar.

          >

          Any ideas?

          >

          Thanks anyway

          >

          • 2. Re: How to I validate a list selection
            JMCarrenoCanas Level 1

            Michael, this is my code:

             

            formItem.label=resourceManager.getString('moreResources','TPF.QueryForm.'+type);
                            var listInState:IsInState=new IsInState();                                   // extends from list
                            listInState.loadData(children);                                                    //  method to load data and add it to the custom list
                            if (required){
                                var validator:NumberValidator= new NumberValidator();       // create the new validator
                                validator.source=listInState;
                                validator.property="selectedIndex";
                                validator.minValue=0;
                                validator.lowerThanMinError="Select one item please";

                                validators.addItem(validator);                                                 // add the validator to a validator`s array which is validate on click button
                            }
                            formItem.addChild(listInState);

            • 3. Re: How to I validate a list selection
              Barna Biro Level 3

              Hi there,

               

              I think that you're overcomplicating it a bit. Simply do this:

               

              if (yourList.selectedItem == null)
              {
                  // Throw an Aler or whatever error message you want.
                  Alert.show("Please select an item.");
              }
              else
              {
                  // Do whatever you want with the selected item.
              }
              

               

              In my opinion, you are just overcomplicating it with validators and who knows what. Still, even if you want to use a validator then I'd rather check to see if the user has selected an item with selectedItem than try to solve the problem with the help of indexes.

               

              Just my 5 cents,

              With best regards,

              Barna Biro

              • 4. Re: How to I validate a list selection
                JMCarrenoCanas Level 1

                Barna,

                 

                It`s a requirement of the proyect to validate the list selection. The list is component of a form.

                 

                I`m using validator because when a user makes a mistake in the validation it`s necesary to show the same skin error in all fields.

                 

                Thanks for your aerly response

                • 5. Re: How to I validate a list selection
                  Barna Biro Level 3

                  I understand. Could you maybe provide a screenshot and a short description ( a Use Case ) of what the user is supposed to do and how should the application react to what he is doing? It would help me understand the problem much better and hopefully to provide a correct solution ( at the moment, it's not clear to me how the list is linked to the form ).

                   

                  With best regards,

                  Barna Biro