webcomponentsjs icon indicating copy to clipboard operation
webcomponentsjs copied to clipboard

Shimmed HTMLFormControlsCollection's elements property is incompatible

Open patternseek opened this issue 10 years ago • 2 comments

The elements member of a shimmed/wrapped HTMLFormControlsCollection (and presumably also HTMLCollection) only exposes elements by index, not by name. Also the namedItem() function isn't present. Is this intentional? I may be doing something stupid but this breaks code unrelated to web components on a page where the full webcomponentsjs polyfill is used. My specific use case is to have an instance of ProseMirror on a page which also has web components that need the Shadow Dom polyfill. When the polyfill is present ProseMirror breaks as it's trying to access form elements like this: form.elements["elementName"].

This alerts "false", "false":

<!doctype html>
<html>
<head>
    <title>Test</title>
    <script src="../../webcomponentsjs/webcomponents.js"></script>
</head>
<body>
    <form id="testForm">
        <input name="field0">
        <input name="field1">
    </form>
    <script>
        window.addEventListener("WebComponentsReady", function(){
            var el = document.querySelector('#testForm');
            alert( typeof el.elements.namedItem === "function" );
            alert( typeof el.elements["field0"] !== "undefined" );
        });
    </script>
</body>
</html>

Whereas this alerts "true", "true":

<!doctype html>
<html>
<head>
    <title>Test</title>
</head>
<body>
    <form id="testForm">
        <input name="field0">
        <input name="field1">
    </form>
    <script>
        var el = document.querySelector('#testForm');
        alert( typeof el.elements.namedItem === "function" );
        alert( typeof el.elements["field0"] !== "undefined" );
    </script>
</body>
</html>

patternseek avatar Dec 30 '15 15:12 patternseek

Ah. Is this a duplicate of #217?

patternseek avatar Dec 30 '15 15:12 patternseek

I'm going to say yes and tentatively close this as a duplicate :)

notwaldorf avatar Jan 23 '17 23:01 notwaldorf