# HG changeset patch # User Nicholas Jillings # Date 1453818043 0 # Node ID 329a558b7be5ce88496d6fb6b76d2deb3da29c6b # Parent f0fa49f5bbb0a0ad77a7903413e708f1a83f770a Feature #1234: Completed fix diff -r f0fa49f5bbb0 -r 329a558b7be5 core.js --- a/core.js Tue Jan 26 13:52:56 2016 +0000 +++ b/core.js Tue Jan 26 14:20:43 2016 +0000 @@ -549,9 +549,18 @@ textArea.rows = "10"; break; } + if (node.response == undefined) { + node.response = ""; + } else { + textArea.value = node.response; + } this.popupResponse.appendChild(textArea); textArea.focus(); } else if (node.specification.type == 'checkbox') { + if (node.response == undefined) { + node.response = Array(node.specification.options.length); + } + var index = 0; for (var option of node.specification.options) { var input = document.createElement('input'); input.id = option.name; @@ -564,8 +573,18 @@ hold.appendChild(input); hold.appendChild(span); this.popupResponse.appendChild(hold); + if (node.response[index] != undefined){ + if (node.response[index].checked == true) { + input.checked = "true"; + } + } + index++; } } else if (node.specification.type == 'radio') { + if (node.response == undefined) { + node.response = {name: "", text: ""}; + } + var index = 0; for (var option of node.specification.options) { var input = document.createElement('input'); input.id = option.name; @@ -579,6 +598,9 @@ hold.appendChild(input); hold.appendChild(span); this.popupResponse.appendChild(hold); + if (input.id == node.response.name) { + input.checked = "true"; + } } } else if (node.specification.type == 'number') { var input = document.createElement('input'); @@ -586,6 +608,9 @@ if (node.min != null) {input.min = node.specification.min;} if (node.max != null) {input.max = node.specification.max;} if (node.step != null) {input.step = node.specification.step;} + if (node.response != undefined) { + input.value = node.response; + } this.popupResponse.appendChild(input); } var content_height = Number(this.popup.offsetHeight.toFixed()); @@ -721,39 +746,7 @@ // Triggered when the 'Back' button is clicked in the survey if (this.currentIndex > 0) { this.currentIndex--; - var node = this.popupOptions[this.currentIndex]; - if (node.type != 'statement') { - var prevResp = this.responses.childNodes[this.responses.childElementCount-1]; - this.responses.removeChild(prevResp); - } this.postNode(); - if (node.type == 'question') { - this.popupContent.getElementsByTagName('textarea')[0].value = prevResp.textContent; - } else if (node.type == 'checkbox') { - var options = this.popupContent.getElementsByTagName('input'); - var savedOptions = prevResp.getElementsByTagName('option'); - for (var i=0; i