Explorar el Código

handling of checkboxes and radiobuttons

Gildas hace 7 años
padre
commit
ffa449a906
Se han modificado 2 ficheros con 7 adiciones y 0 borrados
  1. 1 0
      lib/single-file/doc-helper.js
  2. 6 0
      lib/single-file/single-file-core.js

+ 1 - 0
lib/single-file/doc-helper.js

@@ -357,6 +357,7 @@ this.docHelper = this.docHelper || (() => {
 
 	function retrieveInputValues(doc, options) {
 		doc.querySelectorAll("input").forEach(input => input.setAttribute(inputValueAttributeName(options.sessionId), input.value));
+		doc.querySelectorAll("input[type=radio], input[type=checkbox]").forEach(input => input.setAttribute(inputValueAttributeName(options.sessionId), input.checked));
 		doc.querySelectorAll("textarea").forEach(textarea => textarea.setAttribute(inputValueAttributeName(options.sessionId), textarea.value));
 		doc.querySelectorAll("select").forEach(select => {
 			select.querySelectorAll("option").forEach(option => {

+ 6 - 0
lib/single-file/single-file-core.js

@@ -390,6 +390,12 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 				const value = input.getAttribute(DOM.inputValueAttributeName(this.options.sessionId));
 				input.setAttribute("value", value || "");
 			});
+			this.doc.querySelectorAll("input[type=radio], input[type=checkbox]").forEach(input => {
+				const value = input.getAttribute(DOM.inputValueAttributeName(this.options.sessionId));
+				if (value == "true") {
+					input.setAttribute("checked", "");
+				}
+			});
 			this.doc.querySelectorAll("textarea").forEach(textarea => {
 				const value = textarea.getAttribute(DOM.inputValueAttributeName(this.options.sessionId));
 				textarea.textContent = value || "";