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

Commit

Permalink
Merge pull request #462 from Polymer/fix_form_elements
Browse files Browse the repository at this point in the history
fix form.elements -- this is used by NodeBind getAssociatedRadioButtons
  • Loading branch information
John Messerly committed Jun 27, 2014
2 parents bfc202e + a6d36f8 commit b2c730a
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions build.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"src/wrappers/HTMLElement.js",
"src/wrappers/HTMLCanvasElement.js",
"src/wrappers/HTMLContentElement.js",
"src/wrappers/HTMLFormElement.js",
"src/wrappers/HTMLImageElement.js",
"src/wrappers/HTMLShadowElement.js",
"src/wrappers/HTMLTemplateElement.js",
Expand Down
1 change: 1 addition & 0 deletions shadowdom.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
'src/wrappers/HTMLElement.js',
'src/wrappers/HTMLCanvasElement.js',
'src/wrappers/HTMLContentElement.js',
'src/wrappers/HTMLFormElement.js',
'src/wrappers/HTMLImageElement.js',
'src/wrappers/HTMLShadowElement.js',
'src/wrappers/HTMLTemplateElement.js',
Expand Down
35 changes: 35 additions & 0 deletions src/wrappers/HTMLFormElement.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2014 The Polymer Authors. All rights reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*/

(function(scope) {
'use strict';

var HTMLElement = scope.wrappers.HTMLElement;
var mixin = scope.mixin;
var registerWrapper = scope.registerWrapper;
var wrapHTMLCollection = scope.wrapHTMLCollection;
var unwrap = scope.unwrap;

var OriginalHTMLFormElement = window.HTMLFormElement;

function HTMLFormElement(node) {
HTMLElement.call(this, node);
}
HTMLFormElement.prototype = Object.create(HTMLElement.prototype);
mixin(HTMLFormElement.prototype, {
get elements() {
// Note: technically this should be an HTMLFormControlsCollection, but
// that inherits from HTMLCollection, so should be good enough. Spec:
// http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-interfaces.html#htmlformcontrolscollection
return wrapHTMLCollection(unwrap(this).elements);
}
});

registerWrapper(OriginalHTMLFormElement, HTMLFormElement,
document.createElement('form'));

scope.wrappers.HTMLFormElement = HTMLFormElement;
})(window.ShadowDOMPolyfill);
17 changes: 17 additions & 0 deletions test/js/HTMLFormElement.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright 2014 The Polymer Authors. All rights reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*/

suite('HTMLFormElement', function() {

test('elements', function() {
var form = document.createElement('form');
var input = document.createElement('input');
form.appendChild(input);
assert.instanceOf(form.elements, HTMLCollection);
assert.equal(form.elements.length, 1);
});

});
1 change: 1 addition & 0 deletions test/test.main.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ var modules = [
'HTMLContentElement.js',
'HTMLElement.js',
'HTMLFieldSetElement.js',
'HTMLFormElement.js',
'HTMLHeadElement.js',
'HTMLHtmlElement.js',
'HTMLImageElement.js',
Expand Down

0 comments on commit b2c730a

Please sign in to comment.