Mercurial > hg > webaudioevaluationtool
comparison js/core.js @ 2566:172c76d9414b
Survey checkbox now supports min and max to define how many options should be selected #17
author | Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk> |
---|---|
date | Thu, 08 Sep 2016 16:20:18 +0100 |
parents | f0b0809c7ee5 |
children | 521aa69517c4 |
comparison
equal
deleted
inserted
replaced
2565:bc6edd2c8772 | 2566:172c76d9414b |
---|---|
913 } else if (node.specification.type == 'checkbox') { | 913 } else if (node.specification.type == 'checkbox') { |
914 // Must extract checkbox data | 914 // Must extract checkbox data |
915 console.log("Checkbox: "+ node.specification.statement); | 915 console.log("Checkbox: "+ node.specification.statement); |
916 var inputs = this.popupResponse.getElementsByTagName('input'); | 916 var inputs = this.popupResponse.getElementsByTagName('input'); |
917 node.response = []; | 917 node.response = []; |
918 var numChecked = 0; | |
919 for (var i=0; i<node.specification.options.length; i++) { | |
920 if (inputs[i].checked) {numChecked++;} | |
921 } | |
922 if (node.specification.min != undefined) { | |
923 if (node.specification.max == undefined) { | |
924 if (numChecked < node.specification.min) { | |
925 var msg = "You must select at least "+node.specification.min+" option"; | |
926 if (node.specification.min > 1) { | |
927 msg += "s"; | |
928 } | |
929 interfaceContext.lightbox.post("Error",msg); | |
930 return; | |
931 } | |
932 } | |
933 else { | |
934 if (numChecked < node.specification.min || numChecked > node.specification.max) { | |
935 if (node.specification.min == node.specification.max) { | |
936 interfaceContext.lightbox.post("Error","You must only select "+node.specification.min); | |
937 } else { | |
938 interfaceContext.lightbox.post("Error","You must select between "+node.specification.min+" and "+node.specification.max); | |
939 } | |
940 return; | |
941 } | |
942 } | |
943 } | |
918 for (var i=0; i<node.specification.options.length; i++) { | 944 for (var i=0; i<node.specification.options.length; i++) { |
919 node.response.push({ | 945 node.response.push({ |
920 name: node.specification.options[i].name, | 946 name: node.specification.options[i].name, |
921 text: node.specification.options[i].text, | 947 text: node.specification.options[i].text, |
922 checked: inputs[i].checked | 948 checked: inputs[i].checked |