cloning-steps.html (2263B)
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 <link rel="author" title="Matthew Phillips" href="mailto:matthew@matthewphillips.info"> 9 10 <script src="/resources/testharness.js"></script> 11 <script src="/resources/testharnessreport.js"></script> 12 13 <script type=module> 14 import inputTypes from "./input-types.js"; 15 16 test(function() { 17 var input = document.createElement("input"); 18 input.value = "foo bar"; 19 20 var copy = input.cloneNode(); 21 assert_equals(copy.value, "foo bar"); 22 }, "input element's value should be cloned"); 23 24 test(function() { 25 var input = document.createElement("input"); 26 input.value = "foo bar"; 27 28 var copy = input.cloneNode(); 29 copy.setAttribute("value", "something else"); 30 31 assert_equals(copy.value, "foo bar"); 32 }, "input element's dirty value flag should be cloned, so setAttribute doesn't affect the cloned input's value"); 33 34 for (const inputType of inputTypes) { 35 test(function() { 36 var input = document.createElement("input"); 37 input.setAttribute("type", inputType); 38 input.indeterminate = true; 39 40 var copy = input.cloneNode(); 41 assert_equals(copy.indeterminate, true); 42 }, `input[type=${inputType}] element's indeterminateness should be cloned`); 43 44 test(function() { 45 var input = document.createElement("input"); 46 input.setAttribute("type", inputType); 47 input.checked = true; 48 49 var copy = input.cloneNode(); 50 assert_equals(copy.checked, true); 51 }, `input[type=${inputType}] element's checkedness should be cloned`); 52 53 test(function() { 54 var input = document.createElement("input"); 55 input.setAttribute("type", inputType); 56 input.checked = false; 57 58 var copy = input.cloneNode(); 59 copy.setAttribute("checked", "checked"); 60 61 assert_equals(copy.checked, false); 62 }, `input[type=${inputType}] element's dirty checkedness should be cloned, so setAttribute doesn't affect the cloned input's checkedness`); 63 } 64 </script>