Skip to content
This repository was archived by the owner on Mar 13, 2018. It is now read-only.

Commit b2c730a

Browse files
author
John Messerly
committed
Merge pull request #462 from Polymer/fix_form_elements
fix form.elements -- this is used by NodeBind getAssociatedRadioButtons
2 parents bfc202e + a6d36f8 commit b2c730a

File tree

5 files changed

+55
-0
lines changed

5 files changed

+55
-0
lines changed

build.json

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"src/wrappers/HTMLElement.js",
2020
"src/wrappers/HTMLCanvasElement.js",
2121
"src/wrappers/HTMLContentElement.js",
22+
"src/wrappers/HTMLFormElement.js",
2223
"src/wrappers/HTMLImageElement.js",
2324
"src/wrappers/HTMLShadowElement.js",
2425
"src/wrappers/HTMLTemplateElement.js",

shadowdom.js

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
'src/wrappers/HTMLElement.js',
3636
'src/wrappers/HTMLCanvasElement.js',
3737
'src/wrappers/HTMLContentElement.js',
38+
'src/wrappers/HTMLFormElement.js',
3839
'src/wrappers/HTMLImageElement.js',
3940
'src/wrappers/HTMLShadowElement.js',
4041
'src/wrappers/HTMLTemplateElement.js',

src/wrappers/HTMLFormElement.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2014 The Polymer Authors. All rights reserved.
3+
* Use of this source code is governed by a BSD-style
4+
* license that can be found in the LICENSE file.
5+
*/
6+
7+
(function(scope) {
8+
'use strict';
9+
10+
var HTMLElement = scope.wrappers.HTMLElement;
11+
var mixin = scope.mixin;
12+
var registerWrapper = scope.registerWrapper;
13+
var wrapHTMLCollection = scope.wrapHTMLCollection;
14+
var unwrap = scope.unwrap;
15+
16+
var OriginalHTMLFormElement = window.HTMLFormElement;
17+
18+
function HTMLFormElement(node) {
19+
HTMLElement.call(this, node);
20+
}
21+
HTMLFormElement.prototype = Object.create(HTMLElement.prototype);
22+
mixin(HTMLFormElement.prototype, {
23+
get elements() {
24+
// Note: technically this should be an HTMLFormControlsCollection, but
25+
// that inherits from HTMLCollection, so should be good enough. Spec:
26+
// http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-interfaces.html#htmlformcontrolscollection
27+
return wrapHTMLCollection(unwrap(this).elements);
28+
}
29+
});
30+
31+
registerWrapper(OriginalHTMLFormElement, HTMLFormElement,
32+
document.createElement('form'));
33+
34+
scope.wrappers.HTMLFormElement = HTMLFormElement;
35+
})(window.ShadowDOMPolyfill);

test/js/HTMLFormElement.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright 2014 The Polymer Authors. All rights reserved.
3+
* Use of this source code is governed by a BSD-style
4+
* license that can be found in the LICENSE file.
5+
*/
6+
7+
suite('HTMLFormElement', function() {
8+
9+
test('elements', function() {
10+
var form = document.createElement('form');
11+
var input = document.createElement('input');
12+
form.appendChild(input);
13+
assert.instanceOf(form.elements, HTMLCollection);
14+
assert.equal(form.elements.length, 1);
15+
});
16+
17+
});

test/test.main.js

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ var modules = [
8585
'HTMLContentElement.js',
8686
'HTMLElement.js',
8787
'HTMLFieldSetElement.js',
88+
'HTMLFormElement.js',
8889
'HTMLHeadElement.js',
8990
'HTMLHtmlElement.js',
9091
'HTMLImageElement.js',

0 commit comments

Comments
 (0)