Skip to content

Commit

Permalink
Merge pull request #58 from jamesallardice/55-form-attr
Browse files Browse the repository at this point in the history
Prevent JS error in IE when the form attribute is used on an input
  • Loading branch information
James Allardice committed Nov 29, 2013
2 parents f8d97cd + 3193e39 commit e522c7f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@
if (elem.form) {
form = elem.form;

// If the type of the property is a string then we have a "form" attribute and need to get the real form
if (typeof form === "string") {
form = document.getElementById(form);
}

// Set a flag on the form so we know it's been handled (forms can contain multiple inputs)
if (!form.getAttribute(ATTR_FORM_HANDLED)) {
Utils.addEventListener(form, "submit", makeSubmitHandler(form));
Expand Down
7 changes: 6 additions & 1 deletion test/default/tests.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@
<button type="submit">Submit form</button>
</form>

<!-- Polyfill should handle input elements that specify their form with an attribute -->
<form method="get" action="" id="form2">
<input type="text" form="form2" placeholder="Test form attribute">
</form>

<script src="../../build/Placeholders.js"></script>
<script src="tests.js"></script>
</body>
</html>
</html>

0 comments on commit e522c7f

Please sign in to comment.