Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Adds a test for the html5 'form' attribute. #640

Merged
merged 3 commits into from

3 participants

@danielchatfield

Credit goes to Ryan Seddon for the test.

@danielchatfield

Closing this for now whilst I explore a better way of detecting it.

@danielchatfield

Tested on IE 6 - 10, Chrome, Opera, Firefox and seems to be working lovely now - I just had to slightly alter Ryan's code.

@aFarkas
Owner

@danielchatfield

The hole try catch block looked a little bit suspicious to me. As it turns out it was only added to workaround a bug in IE6/7 (busted distinction between content attributes and idl attributes).

I think you should document this error. Without a comment other developers could think that this code is not bulletproof, but it is :-)

@danielchatfield

@aFarkas Thanks - will do

@ryanseddon
Owner

We should let this sit for a while and see if anyone else has a better solution.

From my findings both the form and input elements need to exist in the DOM to get correct results.

@aFarkas
Owner

The error is not thrown because IE6/7 doesn't let you append the form. It is thrown, because we try to change the form attribute, which is readonly. And if the attribute is readonly, the feature can not be supported. So the catch part is a real part of the test.

I made a jsfiddle to make this more clear.

@aFarkas
Owner

@ryanseddon

I would like move this forward. What exactly is your problem with the current solution? I changed the detection to use document.createAttribute, so that all browsers have the same code path.

You can find my new proposal here: http://jsfiddle.net/kmNt2/3/

@ryanseddon
Owner

@aFarkas ok fair enough the createAttribute check is a good idea I'm happy to move with this one then.

@danielchatfield

Updated the test.

@aFarkas aFarkas merged commit 3102b23 into Modernizr:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 23, 2012
  1. @danielchatfield

    Added 'formattribute' test

    danielchatfield authored
    Fixes #639
  2. @danielchatfield
Commits on Jul 25, 2012
  1. @danielchatfield
This page is out of date. Refresh to see the latest.
Showing with 29 additions and 0 deletions.
  1. +29 −0 feature-detects/forms-formattribute.js
View
29 feature-detects/forms-formattribute.js
@@ -0,0 +1,29 @@
+// Detects whether input form="form_id" is available on the platform
+// E.g. IE 10 (and below), don't support this
+Modernizr.addTest("formattribute", function() {
+ var form = document.createElement("form"),
+ input = document.createElement("input"),
+ div = document.createElement("div"),
+ id = "formtest"+(new Date().getTime()),
+ attr,
+ bool = false;
+
+ form.id = id;
+
+ //IE6/7 confuses the form idl attribute and the form content attribute
+ if(document.createAttribute){
+ attr = document.createAttribute("form");
+ attr.nodeValue = id;
+ input.setAttributeNode(attr);
+ div.appendChild(form);
+ div.appendChild(input);
+
+ document.documentElement.appendChild(div);
+
+ bool = form.elements.length === 1 && input.form == form;
+
+ div.parentNode.removeChild(div);
+ }
+
+ return bool;
+});
Something went wrong with that request. Please try again.