Skip to content

Input's form attribute and document submit handler produce an IE8 error #2332

@igor10k

Description

@igor10k

When you use an input with form attribute while also handling the document's submit event you get an error in IE8.

Here's an easy way to reproduce it.

<html>
<body>
  <input type="text" form="test">
  <form action="" id="test"></form>
  <script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
  <script>
    $(document).on('submit', 'form', function () {});
  </script>
</body>
</html>

When you click the input in IE8 you get this error.

screen shot 2015-05-19 at 16 10 42

Here's a jsfiddle http://jsfiddle.net/1g19xt3p/1/
And since jsfiddle doesn't work in IE8 here's a direct link to the result https://jsfiddle.net/1g19xt3p/1/embedded/result/

A small research showed that here's the code responsible

jQuery.event.special.submit = {
  setup: function() {
    // skipped
    jQuery.event.add( this, "click._submit keypress._submit", function( e ) {
      var elem = e.target,
        form = jQuery.nodeName( elem, "input" ) || jQuery.nodeName( elem, "button" ) ? elem.form : undefined;
      if ( form && !jQuery._data( form, "submitBubbles" ) ) {
        // skipped
      }
    });
  },
  // skipped

The thing is elem.form returns the form attribute value in IE8 that is a String and jQuery can't get the data out of a String.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions