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

[Validator] Javascript Validation currently uses unsupported DOM method getAttributeNode("name").

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • None
    • None
    • None
    • Operating System: other
      Platform: PC

    • 37315

    Description

      The use of Element.getAttributeNode("name") is not supported by IE prior to
      version 6. This error was reportedly fixed in COM-2145 but the resolution to
      still uses getAttributeNode("name").

      document.getAttributeNode() is present in:
      ./jakarta-commons/validator/src/javascript/org/apache/commons/validator/javascript/validateFloatRange.js
      ./jakarta-commons/validator/src/javascript/org/apache/commons/validator/javascript/validateShort.js
      ./jakarta-commons/validator/src/javascript/org/apache/commons/validator/javascript/validateMinLength.js
      ./jakarta-commons/validator/src/javascript/org/apache/commons/validator/javascript/validateDate.js
      ./jakarta-commons/validator/src/javascript/org/apache/commons/validator/javascript/validateEmail.js
      ./jakarta-commons/validator/src/javascript/org/apache/commons/validator/javascript/validateByte.js
      ./jakarta-commons/validator/src/javascript/org/apache/commons/validator/javascript/validateIntRange.js
      ./jakarta-commons/validator/src/javascript/org/apache/commons/validator/javascript/validateMask.js
      ./jakarta-commons/validator/src/javascript/org/apache/commons/validator/javascript/validateCreditCard.js
      ./jakarta-commons/validator/src/javascript/org/apache/commons/validator/javascript/validateInteger.js
      ./jakarta-commons/validator/src/javascript/org/apache/commons/validator/javascript/validateMaxLength.js
      ./jakarta-commons/validator/src/javascript/org/apache/commons/validator/javascript/validateFloat.js

      This is issue has also previously been raised in COM-1622, with an appropriate
      patch being supplied.

      Attachments

        1. ASF.LICENSE.NOT.GRANTED--patchIE5.diff
          0.4 kB
          Jeffrey Williams

        Activity

          Firstly, there is no reference to getAttributeNode() in any of the scripts you
          indicate since the fix/patch applied for Firstly, there is no reference to getAttributeNode() in any of the scripts you
          indicate since the fix/patch applied for Bug 35127 refactored the code to get
          the form name into a separate utility method - retrieveFormName() - which is
          located in validateUtilities.js

          Having said that - that script does still use the getAttributeNode() function,
          but IMO its now less of an issue - since anyone wanting IE 5.5 support can
          simply provide their own implementation of that method and configure validator
          to use it.

          Personally I haven't been involved in that change and don't have a copy of IE
          5.5 to test on. If you could supply a patch which resolves this in IE 5.5 then
          I will apply it. It needs to be soon though, if you want it included in
          Validator 1.2.0 - I just finished rolling "release candidate 2" when you posted
          this:

          http://www.mail-archive.com/commons-dev%40jakarta.apache.org/msg68919.html refactored the code to get
          the form name into a separate utility method - retrieveFormName() - which is
          located in validateUtilities.js

          Having said that - that script does still use the getAttributeNode() function,
          but IMO its now less of an issue - since anyone wanting IE 5.5 support can
          simply provide their own implementation of that method and configure validator
          to use it.

          Personally I haven't been involved in that change and don't have a copy of IE
          5.5 to test on. If you could supply a patch which resolves this in IE 5.5 then
          I will apply it. It needs to be soon though, if you want it included in
          Validator 1.2.0 - I just finished rolling "release candidate 2" when you posted
          this:

          http://www.mail-archive.com/commons-dev%40jakarta.apache.org/msg68919.html

          niallp Niall Pemberton added a comment - Firstly, there is no reference to getAttributeNode() in any of the scripts you indicate since the fix/patch applied for Firstly, there is no reference to getAttributeNode() in any of the scripts you indicate since the fix/patch applied for Bug 35127 refactored the code to get the form name into a separate utility method - retrieveFormName() - which is located in validateUtilities.js Having said that - that script does still use the getAttributeNode() function, but IMO its now less of an issue - since anyone wanting IE 5.5 support can simply provide their own implementation of that method and configure validator to use it. Personally I haven't been involved in that change and don't have a copy of IE 5.5 to test on. If you could supply a patch which resolves this in IE 5.5 then I will apply it. It needs to be soon though, if you want it included in Validator 1.2.0 - I just finished rolling "release candidate 2" when you posted this: http://www.mail-archive.com/commons-dev%40jakarta.apache.org/msg68919.html refactored the code to get the form name into a separate utility method - retrieveFormName() - which is located in validateUtilities.js Having said that - that script does still use the getAttributeNode() function, but IMO its now less of an issue - since anyone wanting IE 5.5 support can simply provide their own implementation of that method and configure validator to use it. Personally I haven't been involved in that change and don't have a copy of IE 5.5 to test on. If you could supply a patch which resolves this in IE 5.5 then I will apply it. It needs to be soon though, if you want it included in Validator 1.2.0 - I just finished rolling "release candidate 2" when you posted this: http://www.mail-archive.com/commons-dev%40jakarta.apache.org/msg68919.html

          Created an attachment (id=16845)
          IE 5 fix for getAttributeNode() in validateUtilities.js

          This is a simple fix changing the getAttributeNode("name") function to
          getAttribute("name") to allow javascript validation to work in IE 5+.

          jwilliams@judcom.nsw.gov.au Jeffrey Williams added a comment - Created an attachment (id=16845) IE 5 fix for getAttributeNode() in validateUtilities.js This is a simple fix changing the getAttributeNode("name") function to getAttribute("name") to allow javascript validation to work in IE 5+.

          I tried your patch out in the struts-examples webapp, using IE6 and it caused a
          problem.

          The Form happended to have an text input field with name="name" and the
          getAttribute("name") method returned the input field rather than the name of
          the form.

          Also looking at this method - seems inconsistent to me that it used form.id to
          check the id and form.getAttributeNode("name") for the name. Maybe something
          like the following would be better:

          function retrieveFormName(form) {

          if (form.getAttributeNode) {
          if (form.getAttributeNode("id") &&
          form.getAttributeNode("id").value)

          { return form.getAttributeNode("id").value; }

          else

          { return form.getAttributeNode("name").value; }

          } else if (form.getAttribute) {
          if (form.getAttribute("id"))

          { return form.getAttribute("id"); }

          else

          { return form.getAttribute("name"); }

          } else {
          if (form.id)

          { return form.id; }

          else

          { return form.name; }

          }
          }

          Any comments appreciated as javascript isn't my forte.

          niallp Niall Pemberton added a comment - I tried your patch out in the struts-examples webapp, using IE6 and it caused a problem. The Form happended to have an text input field with name="name" and the getAttribute("name") method returned the input field rather than the name of the form. Also looking at this method - seems inconsistent to me that it used form.id to check the id and form.getAttributeNode("name") for the name. Maybe something like the following would be better: function retrieveFormName(form) { if (form.getAttributeNode) { if (form.getAttributeNode("id") && form.getAttributeNode("id").value) { return form.getAttributeNode("id").value; } else { return form.getAttributeNode("name").value; } } else if (form.getAttribute) { if (form.getAttribute("id")) { return form.getAttribute("id"); } else { return form.getAttribute("name"); } } else { if (form.id) { return form.id; } else { return form.name; } } } Any comments appreciated as javascript isn't my forte.

          I tested your suggestion in IE 5 and it failed when it had a input field with
          name="name".

          I made a slight change and tested in IE 5,6, and latest firefox and it appears
          to work fine:

          function retrieveFormName(form) {

          if (form.getAttributeNode) {
          if (form.getAttributeNode("id") &&
          form.getAttributeNode("id").value)

          { return form.getAttributeNode("id").value; }

          else

          { return form.getAttributeNode("name").value; }

          } else if (form.getAttribute) {
          if (form.getAttribute("id"))

          { return form.getAttribute("id"); }

          else

          { return form.attributes["name"]; }

          } else {
          if (form.id)

          { return form.id; }

          else

          { return form.name; }

          }
          }

          jwilliams@judcom.nsw.gov.au Jeffrey Williams added a comment - I tested your suggestion in IE 5 and it failed when it had a input field with name="name". I made a slight change and tested in IE 5,6, and latest firefox and it appears to work fine: function retrieveFormName(form) { if (form.getAttributeNode) { if (form.getAttributeNode("id") && form.getAttributeNode("id").value) { return form.getAttributeNode("id").value; } else { return form.getAttributeNode("name").value; } } else if (form.getAttribute) { if (form.getAttribute("id")) { return form.getAttribute("id"); } else { return form.attributes["name"]; } } else { if (form.id) { return form.id; } else { return form.name; } } }

          Jeffrey, thanks for the feedback - I've applied this change with the
          modification you suggested.

          http://svn.apache.org/viewcvs?rev=330237&view=rev

          niallp Niall Pemberton added a comment - Jeffrey, thanks for the feedback - I've applied this change with the modification you suggested. http://svn.apache.org/viewcvs?rev=330237&view=rev
          john@h3.com John G. Norman added a comment -

          Guys, there is a bug in http://svn.apache.org/viewcvs?rev=330237&view=rev (see
          Comment 5). The code there, a bit different from what Jeffrey gives in Comment
          4, goes:

          function retrieveFormName(form) {
          if (form.getAttributeNode) {
          if (form.getAttributeNode("id") && form.getAttributeNode("id").value)

          { return form.getAttributeNode("id").value; }

          else

          { return form.getAttributeNode("name").value; }

          } else if (form.getAttribute) {
          if (form.getAttribute("id"))

          { return form.getAttribute("id"); }

          else

          { form.attributes["name"]; // *****PROBLEM***** }

          } else {
          if (form.id)

          { return form.id; }

          else

          { return form.name; }

          }
          }

          The problem marked above is that there is no return statement. I.e., it should be:

          return form.attributes["name"];

                  • Because of this, the Javascript produces an error on IE 5.0 and 5.5.
          john@h3.com John G. Norman added a comment - Guys, there is a bug in http://svn.apache.org/viewcvs?rev=330237&view=rev (see Comment 5). The code there, a bit different from what Jeffrey gives in Comment 4, goes: function retrieveFormName(form) { if (form.getAttributeNode) { if (form.getAttributeNode("id") && form.getAttributeNode("id").value) { return form.getAttributeNode("id").value; } else { return form.getAttributeNode("name").value; } } else if (form.getAttribute) { if (form.getAttribute("id")) { return form.getAttribute("id"); } else { form.attributes["name"]; // *****PROBLEM***** } } else { if (form.id) { return form.id; } else { return form.name; } } } The problem marked above is that there is no return statement. I.e., it should be: return form.attributes ["name"] ; Because of this, the Javascript produces an error on IE 5.0 and 5.5.

          (In reply to comment #6)
          > Guys, there is a bug in http://svn.apache.org/viewcvs?rev=330237&view=rev

          This has already been raised (see COM-2690) and fixed:

          http://www.mail-archive.com/user%40struts.apache.org/msg39542.html
          http://svn.apache.org/viewcvs.cgi?rev=366458&view=rev

          Please could you check the latest source in subversion before re-opening
          tickets:

          http://jakarta.apache.org/commons/validator/cvs-usage.html

          Thanks

          Niall

          niallp Niall Pemberton added a comment - (In reply to comment #6) > Guys, there is a bug in http://svn.apache.org/viewcvs?rev=330237&view=rev This has already been raised (see COM-2690 ) and fixed: http://www.mail-archive.com/user%40struts.apache.org/msg39542.html http://svn.apache.org/viewcvs.cgi?rev=366458&view=rev Please could you check the latest source in subversion before re-opening tickets: http://jakarta.apache.org/commons/validator/cvs-usage.html Thanks Niall

          People

            Unassigned Unassigned
            jwilliams@judcom.nsw.gov.au Jeffrey Williams
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: