9 Replies Latest reply on Dec 6, 2008 1:06 PM by Francisc

    "Cancel" Validation

    Francisc Level 3
      This is probably very easy... but how can I cancel validation triggered by Validators.validateAll(validatorsListArray) by pressing a Button?

      I change between 2 states and some TextInputs are kept. I don't want them to have the red border etc that comes with validation failure.

      Thank you!
        • 1. Re: "Cancel" Validation
          John Hall Level 4
          When you want to remove the red box, set the errorString of the control to "".
          • 2. Re: "Cancel" Validation
            rtalton Level 4
            John: Way cool! I needed this info, thanks!
            Only issue I had was that it also prevents the tooltip from showing with the error message, but I use an Alert box to get that info to the user anyway.

            While incorporating this new-found gem into an existing app, I went ahead and pulled out code to give you an example of how to run validators, set props, display helpful error messages, etc. Knowledge I could have used when I started using validators for Forms. I hope it is useful.

            Link to application (with source view):
            (Link will be active for a few days only)

            • 3. Re: "Cancel" Validation
              Francisc Level 3
              I've downloaded the ZIP and will be importing it into Flex to have a detailed look! :)

              Thank you!
              • 4. Re: "Cancel" Validation
                Francisc Level 3
                Great example, rtalton! :)
                Your comments made it easy reading. And I learned how to put that damn required star (*) when a field is required! :)) I always wondered how that's done!

                Thank you!
                • 5. Re: "Cancel" Validation
                  rtalton Level 4
                  Glad it was helpful. I just wish setting errorstring='"" didn't prevent the default tooltip from appearing. And, also on my wish list, a way to put the red asterisk on a required field's label to the left of the label's text, instead of it being forced to the right of the text. Guess I'm being too picky now.
                  I'm gonna have to get into extending components and overriding props, maybe. >shudder<
                  • 6. Re: &quot;Cancel&quot; Validation
                    rtalton Level 4
                    I made some changes to make this work better.

                    I used both the validator's triggerEvent property and the textInput's errorColor property to get the results I wanted. It works well. I change the triggerEvent just before clearing the textInput fields, then change the triggerEvent back. This keeps the validation from being called again while resetting the form.

                    Instead of setting the border color, I found the errorColor property, which is more to the point. Now I really don't need the "validHandler" to change the border color; it's done automatically.

                    • 7. Re: &quot;Cancel&quot; Validation
                      Francisc Level 3
                      Yup, it better optimized! :)

                      Only one thing now: if you Reset the form then select a text field, then select the other text field (selection means click in the field), the first one will retain its green border. Minor setback...

                      To add to what you were saying, I was searching for a way to move the red * to the right of the input field to be like this:

                      Name: [ text input] *
                      • 8. Re: &quot;Cancel&quot; Validation
                        rtalton Level 4
                        Clicking in a text field, then clicking away from it causes the validator to run (the valueCommit event runs). This is normal behavior. Since the field has required=true, the validation does not pass (no text was input), and the textInput is then highlighted with the error color. So you'd have to allow an empty field to validate to avoid the error color being shown, and this is probably not what you want.

                        One way to prevent this is to NOT validate the fields until you are ready to submit the entire Form's contents. But I prefer giving feedback as they move from field to field, instead of waiting until they submit all of the data by clicking the button.
                        • 9. Re: &quot;Cancel&quot; Validation
                          Francisc Level 3
                          Hm... I think setting triggerEvent='' in the validator will stop it from auto-validating and only work when you press the login button.