Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-2270

Generated JavaScript for validators does not honor the short-circuit attribute

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.10
    • 2.1.1
    • XML Validators
    • None
    • Patch

    Description

      When you put several validators on a field, like a required and a regex validator, you can specify that the second validator should not be run if the first one fails by setting the short-circuit attribute. However, when you set validate='true' on a form, the JavaScript that is generated does not honor the short-circuit attribute. It will always run both validations.

      The JavaScript is generated by the Freemarker code in form-close-validate.ftl

      I fixed this for my app by adding "var continueValidation = true;" outside the loop, then adding "<#if validator.shortCircuit>continueValidation = false;</#if>" on the line after "errors = true;" in each 'if' block. Then added 'continueValidation && ' to the front of each if.

      This seemed to work just fine.

      Attachments

        1. form-close-validate.ftl
          5 kB
          Aaron Freeman

        Issue Links

          Activity

            People

              mrdon Donald J. Brown
              freeaaron Aaron Freeman
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: