Skip to content

Commit 9ade70e

Browse files
matthewpdomenic
authored andcommitted
Implement the cloning steps for input elements
This implements the cloning steps for input elements by copying over the value, checkedness, dirty value, and dirty checkedness properties to the cloned input.
1 parent 5d66130 commit 9ade70e

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

lib/jsdom/living/nodes/HTMLInputElement-impl.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ const Event = require("../generated/Event");
77
const mapper = require("../../utils").mapper;
88
const createHTMLCollection = require("../../living/html-collection").create;
99
const DOMException = require("../../web-idl/DOMException");
10-
const domSymbolTree = require("../helpers/internal-constants").domSymbolTree;
10+
const internalConstants = require("../helpers/internal-constants");
11+
const domSymbolTree = internalConstants.domSymbolTree;
12+
const cloningSteps = internalConstants.cloningSteps;
1113
const closest = require("../helpers/traversal").closest;
1214
const isDisabled = require("../helpers/form-controls").isDisabled;
1315

@@ -380,6 +382,13 @@ class HTMLInputElementImpl extends HTMLElementImpl {
380382
}
381383
this.setAttribute("size", String(value));
382384
}
385+
386+
[cloningSteps](copy, node) {
387+
copy._value = node._value;
388+
copy._checkedness = node._checkedness;
389+
copy._dirtyValue = node._dirtyValue;
390+
copy._dirtyCheckedness = node._dirtyCheckedness;
391+
}
383392
}
384393

385394
module.exports = {

test/web-platform-tests/to-upstream.js

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ describe("Local tests in Web Platform Test format (to-upstream)", () => {
1717
"dom/nodes/Element-tagName.html",
1818
"dom/nodes/attributes-namednodemap.html",
1919
"dom/nodes/getElementsByClassName-32.html",
20+
"dom/nodes/Node-cloneNode-input.html",
2021
"dom/nodes/Node-isEqualNode.html",
2122
"dom/nodes/Node-mutation-adoptNode.html",
2223
"domparsing/DOMParser-dont-upstream.html",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8">
3+
<title>Cloning of input elements</title>
4+
<link rel="help" href="https://dom.spec.whatwg.org/#dom-node-clonenode">
5+
<link rel="help" href="https://dom.spec.whatwg.org/#concept-node-clone">
6+
<link rel="help" href="https://dom.spec.whatwg.org/#concept-node-clone-ext">
7+
<link rel="help" href="https://html.spec.whatwg.org/multipage/forms.html#the-input-element:concept-node-clone-ext">
8+
9+
<script src="/resources/testharness.js"></script>
10+
<script src="/resources/testharnessreport.js"></script>
11+
12+
<script>
13+
"use strict";
14+
15+
test(() => {
16+
const input = document.createElement("input");
17+
input.value = "foo bar";
18+
19+
const copy = input.cloneNode();
20+
assert_equals(copy.value, "foo bar");
21+
}, "input element's value should be cloned");
22+
23+
test(() => {
24+
const input = document.createElement("input");
25+
input.value = "foo bar";
26+
27+
const copy = input.cloneNode();
28+
copy.setAttribute("value", "something else");
29+
30+
assert_equals(copy.value, "foo bar");
31+
}, "input element's dirty value flag should be cloned, so setAttribute doesn't affect the cloned input's value");
32+
33+
test(() => {
34+
const input = document.createElement("input");
35+
input.setAttribute("type", "radio");
36+
input.checked = true;
37+
38+
const copy = input.cloneNode();
39+
assert_equals(copy.checked, true);
40+
}, "input element's checkedness should be cloned");
41+
42+
test(() => {
43+
const input = document.createElement("input");
44+
input.setAttribute("type", "radio");
45+
input.checked = false;
46+
47+
const copy = input.cloneNode();
48+
copy.setAttribute("checked", "checked");
49+
50+
assert_equals(copy.checked, false);
51+
}, "input element's dirty checkedness should be cloned, so setAttribute doesn't affect the cloned input's checkedness");
52+
</script>

0 commit comments

Comments
 (0)