Mercurial > hg > webaudioevaluationtool
changeset 904:b94bb53ce4ac
Added min/max range check to number box survey
author | Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk> |
---|---|
date | Mon, 08 Jun 2015 12:09:53 +0100 |
parents | 3464a477c021 |
children | 4e9ab4f92f20 |
files | core.js example_eval/project.xml |
diffstat | 2 files changed, 25 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/core.js Mon Jun 08 11:56:14 2015 +0100 +++ b/core.js Mon Jun 08 12:09:53 2015 +0100 @@ -49,7 +49,7 @@ // Creates an object to manage the popup this.popup = null; this.popupContent = null; - this.popupButton = null; + this.buttonProceed = null; this.popupOptions = null; this.currentIndex = null; this.responses = null; @@ -73,10 +73,10 @@ this.popupContent.align = 'center'; this.popup.appendChild(this.popupContent); - this.popupButton = document.createElement('button'); - this.popupButton.className = 'popupButton'; - this.popupButton.innerHTML = 'Next'; - this.popupButton.onclick = function(){popup.buttonClicked();}; + this.buttonProceed = document.createElement('button'); + this.buttonProceed.className = 'popupButton'; + this.buttonProceed.innerHTML = 'Next'; + this.buttonProceed.onclick = function(){popup.proceedClicked();}; this.popup.style.zIndex = -1; this.popup.style.visibility = 'hidden'; blank.style.zIndex = -2; @@ -199,7 +199,7 @@ if (node.step != null) {input.step = node.step;} this.popupContent.appendChild(input); } - this.popupContent.appendChild(this.popupButton); + this.popupContent.appendChild(this.buttonProceed); }; this.initState = function(node) { @@ -223,7 +223,7 @@ } }; - this.buttonClicked = function() { + this.proceedClicked = function() { // Each time the popup button is clicked! var node = this.popupOptions[this.currentIndex]; if (node.type == 'question') { @@ -276,7 +276,20 @@ } else if (node.type == "number") { var input = this.popupContent.getElementsByTagName('input')[0]; if (node.mandatory == true && input.value.length == 0) { - alert('This question is mandatory'); + alert('This question is mandatory. Please enter a number'); + return; + } + var enteredNumber = Number(input.value); + if (enteredNumber == undefined) { + alert('Please enter a valid number'); + return; + } + if (enteredNumber < node.min && node.min != null) { + alert('Number is below the minimum value of '+node.min); + return; + } + if (enteredNumber > node.max && node.max != null) { + alert('Number is above the maximum value of '+node.max); return; } var hold = document.createElement('number'); @@ -286,6 +299,9 @@ } this.currentIndex++; if (this.currentIndex < this.popupOptions.length) { + if(this.currentIndex+1 == this.popupOptions.length) { + this.buttonProceed.textContent = 'Submit'; + } this.postNode(); } else { // Reached the end of the popupOptions
--- a/example_eval/project.xml Mon Jun 08 11:56:14 2015 +0100 +++ b/example_eval/project.xml Mon Jun 08 12:09:53 2015 +0100 @@ -11,7 +11,7 @@ <option id="studio">Studio Mixing</option> <option id="player">Play an instrument</option> </checkbox> - <number id="age">Please enter your age</number> + <number id="age" min="0">Please enter your age</number> <statement>Please listen to all mixes</statement> </PreTest> <PostTest>