Uploaded image for project: 'Commons Validator'
  1. Commons Validator
  2. VALIDATOR-259

[validator] Javascript jcv_handleErrors function fails in IE when field's ancestor is not visible

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Won't Fix
    • 1.3.1 Release
    • None
    • JavaScript
    • None
    • Win XP, Sun JVM 1.4.2_x
      Tomcat 4.1.x, Struts 1.3.8

    Description

      If field is in hidden div (for example) than Javascript validation fails in IE with the following error:

      "Error: Can't move focus to the control because it is invisible, not enabled, or of a type that does not accept focus."

      jcv_handleErrors(messages, focusField) needs to be modified to traverse all parent nodes and check their visibility:

      function jcv_handleErrors(messages, focusField) {
      if (jcv_canFocus(focusField))

      { focusField.focus(); }

      alert(messages.join('\n'));
      }

      function jcv_canFocus(field) {
      var result = true;

      if (field && field != null && typeof(field) != 'undefined') {
      if (field.disabled || field.type == 'hidden')

      { result = false; }
      if (result &&
      field.style &&
      field.style.visibility &&
      field.style.visibility == 'hidden') { result = false; }

      if (result) {
      var parent = field.parentNode;
      if (parent && parent != null && typeof(parent) != 'undefined' && parent.nodeType == 1)

      { result = jcv_canFocus(parent); }

      }
      } else

      { result = false; }

      return result;
      }

      WORKAROUND:

      1. Copy validateUtilities.js file from commons-validator-1.3.1.jar!\org\apache\commons\validator\javascript\validateUtilities.js into classpath under your control and apply patch above.

      2. Modify validator-rules.xml:
      <validator name="includeJavaScriptUtilities" classname="" method=""
      methodParams="" depends="" msg=""
      jsFunction="com.company.path.to.jsfile.validateUtilities" />

      Attachments

        1. VALIDATOR-259.patch
          2 kB
          Bas Zoetekouw

        Issue Links

          Activity

            People

              Unassigned Unassigned
              bas Bas Zoetekouw
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: