Allowed text box sizes to be set, fixed hidden sliders breaking, random text in question text bug fixed, single question button continue working, randomized weirdness on section random question resolved, answer text on multi-slider questions resolved, can have generic scale questions now, removed useless 'previous Text Answer Fill' dialog
This commit is contained in:
parent
18b00e0a2f
commit
1f8d1b3899
4 changed files with 64 additions and 23 deletions
|
|
@ -5,7 +5,7 @@ if (typeof Survey == "undefined") {
|
|||
Survey.Form = new function() {
|
||||
|
||||
var multipleChoice = {'Multiple Choice':1,'Gender':1,'Yes/No':1,'True/False':1,'Ideology':1, 'Race':1,'Party':1,'Education':1};
|
||||
var scale = {'Agree/Disagree':1,'Oppose/Support':1,'Importance':1,
|
||||
var scale = {'Scale':1,'Agree/Disagree':1,'Oppose/Support':1,'Importance':1,
|
||||
'Likelihood':1,'Certainty':1,'Satisfaction':1,'Confidence':1,'Effectiveness':1,'Concern':1,'Risk':1,'Threat':1,'Security':1};
|
||||
var text = {'Text':1, 'Email':1, 'Phone Number':1, 'Text Date':1, 'Currency':1};
|
||||
var slider = {'Slider':1, 'Dual Slider - Range':1, 'Multi Slider - Allocate':1};
|
||||
|
|
@ -17,8 +17,11 @@ Survey.Form = new function() {
|
|||
var verb = 0;
|
||||
var lastSection = 'first';
|
||||
|
||||
var toValidate;
|
||||
|
||||
this.displayQuestions = function(params){
|
||||
|
||||
toValidate = new Array();//clear array
|
||||
var qs = params.questions;
|
||||
var s = params.section;
|
||||
|
||||
|
|
@ -34,12 +37,10 @@ YAHOO.util.Event.addListener("testB", "click", function(){Survey.Comm.callServer
|
|||
document.getElementById('headertitle').style.display='block';
|
||||
}
|
||||
if(lastSection != s.Survey_sectionId || s.everyPageText > 0){
|
||||
//if(qs[0].sequenceNumber == '1' || s.everyPageText > 0){
|
||||
document.getElementById('headertext').style.display = 'block';
|
||||
}
|
||||
|
||||
if((lastSection != s.Survey_sectionId && lastSection != 'first') || s.questionsOnSectionPage != '1'){
|
||||
// if(qs[0].sequenceNumber == '1' && s.questionsOnSectionPage != '1'){
|
||||
if(lastSection != s.Survey_sectionId && s.questionsOnSectionPage != '1'){
|
||||
var span = document.createElement("div");
|
||||
span.innerHTML = "<input type=button id='showQuestionsButton' value='Continue'>";
|
||||
span.style.display = 'block';
|
||||
|
|
@ -55,9 +56,11 @@ YAHOO.util.Event.addListener("testB", "click", function(){Survey.Comm.callServer
|
|||
document.getElementById('headertext').style.display = 'none';
|
||||
}
|
||||
document.getElementById('questions').style.display='inline';
|
||||
Survey.Form.addWidgets(qs);
|
||||
});
|
||||
}else{
|
||||
document.getElementById('questions').style.display='inline';
|
||||
Survey.Form.addWidgets(qs);
|
||||
}
|
||||
lastSection = s.Survey_sectionId;
|
||||
}else{
|
||||
|
|
@ -65,10 +68,9 @@ YAHOO.util.Event.addListener("testB", "click", function(){Survey.Comm.callServer
|
|||
document.getElementById('headertext').style.display = 'block';
|
||||
document.getElementById('questions').style.display='inline';
|
||||
}
|
||||
|
||||
}
|
||||
//Display questions
|
||||
|
||||
var html;
|
||||
this.addWidgets = function(qs){
|
||||
hasFile = false;
|
||||
for(var i = 0; i < qs.length; i++){
|
||||
var q = qs[i];
|
||||
|
|
@ -80,14 +82,21 @@ YAHOO.util.Event.addListener("testB", "click", function(){Survey.Comm.callServer
|
|||
}
|
||||
}
|
||||
|
||||
html += "<hr>";
|
||||
html += "<div class='question'>Q"+q.sequenceNumber+": "+q.questionText+"</div>";
|
||||
//Check if this question should be validated
|
||||
if(q.required == 1){
|
||||
toValidate[q.Survey_questionId] = new Array();
|
||||
}
|
||||
|
||||
|
||||
if(multipleChoice[q.questionType] || scale[q.questionType]){
|
||||
var butts = new Array();
|
||||
verb = 0;
|
||||
for(var x = 0; x < q.answers.length; x++){
|
||||
|
||||
var a = q.answers[x];
|
||||
if(toValidate[a.Survey_questionId]){
|
||||
toValidate[a.Survey_questionId][a.Survey_answerId] = 1;
|
||||
}
|
||||
var b;
|
||||
if(scale[q.questionType]){
|
||||
b = new YAHOO.widget.Button({ type: "checkbox", label: a.recordedAnswer, id: a.Survey_answerId+'button', name: a.Survey_answerId+'button',
|
||||
|
|
@ -101,7 +110,7 @@ YAHOO.util.Event.addListener("testB", "click", function(){Survey.Comm.callServer
|
|||
b.label=a.answerText;
|
||||
}
|
||||
b.setStyle('text-align','center');
|
||||
b.on("click", this.buttonChanged,[b,a.Survey_questionId,q.maxAnswers,butts,qs.length]);
|
||||
b.on("click", this.buttonChanged,[b,a.Survey_questionId,q.maxAnswers,butts,qs.length,a.Survey_answerId]);
|
||||
if(a.verbatim == 1){
|
||||
verb = 1;
|
||||
}
|
||||
|
|
@ -149,7 +158,27 @@ YAHOO.util.Event.addListener("testB", "click", function(){Survey.Comm.callServer
|
|||
|
||||
|
||||
this.formsubmit = function(){
|
||||
Survey.Comm.callServer('','submitQuestions','surveyForm',hasFile);
|
||||
var submit = 1;//boolean for if all was good or not
|
||||
for(var i in toValidate){
|
||||
console.log(i);
|
||||
var answered = 0;
|
||||
for(var z in toValidate[i]){
|
||||
var v = document.getElementById(z).value;
|
||||
if(v != '' && v != undefined){
|
||||
answered = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(answered == 0){
|
||||
submit = 0;
|
||||
document.getElementById(i+'required').innerHTML = "<font color=red>*</font>";
|
||||
}else{
|
||||
document.getElementById(i+'required').innerHTML = "";
|
||||
}
|
||||
}
|
||||
if(submit == 1){
|
||||
Survey.Comm.callServer('','submitQuestions','surveyForm',hasFile);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -242,8 +271,10 @@ YAHOO.util.Event.addListener("testB", "click", function(){Survey.Comm.callServer
|
|||
if(t > total){
|
||||
t -= this.getValue();
|
||||
t = Math.round(t);
|
||||
console.log("setting value: "+scale+" "+step);
|
||||
this.setValue(total-t + scale*step);
|
||||
}else{
|
||||
console.log("setting value in else: "+this.getValue());
|
||||
this.lastValue = this.getValue();
|
||||
document.getElementById(this.input).value = this.getRealValue();
|
||||
document.getElementById(this.input+'show').innerHTML = this.getRealValue();
|
||||
|
|
@ -270,10 +301,13 @@ YAHOO.util.Event.addListener("testB", "click", function(){Survey.Comm.callServer
|
|||
Event.on(document.getElementById(s.input), "blur", manualEntry);
|
||||
|
||||
s.getRealValue = function() {
|
||||
return Math.round(this.getValue() / scale);
|
||||
console.log("getRealValue is getting the real value for the slider:"+this.getValue()+" "+this+" "+scale);
|
||||
|
||||
return Math.round(parseInt(this.getValue()) / scale);
|
||||
}
|
||||
sliders.push(s);
|
||||
document.getElementById(s.input).value = s.getRealValue();
|
||||
console.log("Slider starting value = "+s.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -291,12 +325,15 @@ YAHOO.util.Event.addListener("testB", "click", function(){Survey.Comm.callServer
|
|||
this.showCalendar = function(event,objs){
|
||||
objs[0].show();
|
||||
}
|
||||
|
||||
|
||||
this.buttonChanged = function(event,objs){
|
||||
var b = objs[0];
|
||||
var qid = objs[1];
|
||||
var maxA = objs[2];
|
||||
var butts = objs[3];
|
||||
var qsize = objs[4];
|
||||
var aid = objs[5];
|
||||
max = parseInt(max);
|
||||
if(maxA == 1){
|
||||
for(var i in butts){
|
||||
|
|
@ -321,9 +358,10 @@ YAHOO.util.Event.addListener("testB", "click", function(){Survey.Comm.callServer
|
|||
document.getElementById(qid+'max').innerHTML = parseInt(max+1);
|
||||
document.getElementById(b.hid).value = 1;
|
||||
}
|
||||
//console.log('qsize '+qsize+' verb '+verb);
|
||||
if(qsize == 1 && verb == 0){
|
||||
Survey.Form.formsubmit();
|
||||
if(qsize == 1){
|
||||
if(! document.getElementById(aid+'verbatim')){
|
||||
Survey.Form.formsubmit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}();
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ Survey.AnswerTemplate = new function(){
|
|||
html = html + "<p>Answer Text:\n<textarea name='answerText'>"+params.answerText+"</textArea>\n";
|
||||
html = html + "<p>Recorded Answer\n<textarea name='recordedAnswer'>"+params.recordedAnswer+"</textArea>\n";
|
||||
html = html + "<p>Jump to Question:<input type=text value='"+params.gotoQuestion+"' name=gotoQuestion size=4>";
|
||||
html = html + "<span id='textParams'><p>Text Answer Cols:<input type=text size=2 value='"+params.textCols+"' name=textCols> Rows: \
|
||||
<input type=text size=2 value='"+params.textRows+"' name=textRows> </p></span>";
|
||||
html = html + "<p>Is this the correct answer:\n" +
|
||||
this.makeRadio('isCorrect',[{text:'Yes',value:1},{text:'No',value:0}],params.isCorrect);
|
||||
html = html + "<p>Min:<input type=text value='"+params.min+"' name=min size=2>";
|
||||
|
|
|
|||
|
|
@ -31,11 +31,10 @@ Survey.QuestionTemplate = new function(){
|
|||
html = html + "<p>Randomize answers:";
|
||||
|
||||
html = html+ this.makeRadio('randomizeAnswers',[{text:'Yes',value:1},{text:'No',value:0}],params.randomizeAnswers);
|
||||
html = html + "<p>Previous answers to display:<textarea name='previousAnswerWords' cols=4 rows=2>"+params.previousAnswerWords+"</textarea>";
|
||||
html = html + "<p>Question type:";
|
||||
var questions = ['Agree/Disagree','Certainty','Concern','Confidence','Currency','Date','Date Range','Dual Slider - Range','Education','Effectiveness',
|
||||
'Email','File Upload','Gender','Hidden','Ideology','Importance','Likelihood','Multi Slider - Allocate','Multiple Choice','Oppose/Support',
|
||||
'Party','Phone Number','Race','Risk','Satisfaction','Security','Slider','Text','Text Date','Threat','True/False','Yes/No'];
|
||||
'Party','Phone Number','Race','Risk','Satisfaction','Scale','Security','Slider','Text','Text Date','Threat','True/False','Yes/No'];
|
||||
// var questions = ['Multiple Choice','Gender','Yes/No','True/False','Agree/Disagree','Oppose/Support','Importance','Likelihood','Certainty','Satisfaction',
|
||||
// 'Confidence','Effectiveness','Concern','Risk','Threat','Security','Ideology','Race','Party','Education',
|
||||
// 'Text', 'Email', 'Phone Number', 'Text Date', 'Currency',
|
||||
|
|
@ -50,7 +49,9 @@ Survey.QuestionTemplate = new function(){
|
|||
|
||||
html = html+ this.makeRadio('verticalDisplay',[{text:'Yes',value:1},{text:'No',value:0}],params.verticalDisplay);
|
||||
html = html + "<p>Allow comment:";
|
||||
html = html+ this.makeRadio('allowComment',[{text:'Yes',value:1},{text:'No',value:0}],params.allowComment);
|
||||
html = html + this.makeRadio('allowComment',[{text:'Yes',value:1},{text:'No',value:0}]);
|
||||
html = html + "<span id='commentParams'><p> Cols:<input type=text size=2 value='"+params.commentCols+"' name=commentCols> Rows: \
|
||||
<input type=text size=2 value='"+params.commentRows+"' name=commentRows> </p></span>";
|
||||
html = html + "<p>Maximum number of answers:<input type=text value='"+params.maxAnswers+"' name=maxAnswers size=2>";
|
||||
html = html + "<p>Required:";
|
||||
html = html+ this.makeRadio('required',[{text:'Yes',value:1},{text:'No',value:0}],params.required);
|
||||
|
|
@ -97,9 +98,9 @@ Survey.QuestionTemplate = new function(){
|
|||
var html = '';
|
||||
for(var i in values){
|
||||
if(checked == values[i]['value']){
|
||||
html = html+ "<input type='radio' name='" + name + "' value='" + values[i]['value'] + "' checked>" + values[i]['text'];
|
||||
html = html+ "<input type='radio' id='"+name+"' name='" + name + "' value='" + values[i]['value'] + "' checked>" + values[i]['text'];
|
||||
}else{
|
||||
html = html+ "<input type='radio' name='" + name + "' value='" + values[i]['value'] + "' >" + values[i]['text'];
|
||||
html = html+ "<input type='radio' id='"+name+"' name='" + name + "' value='" + values[i]['value'] + "' >" + values[i]['text'];
|
||||
}
|
||||
}
|
||||
html = html + "\n";
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
<tmpl_loop name='questions'>
|
||||
<hr>
|
||||
<div class='question'>Q<tmpl_var name='sequenceNumber'>: <tmpl_var name='questionText'></div>
|
||||
<div class='question'><span id='<tmpl_var name='Survey_questionId'>required></span>Q<tmpl_var name='sequenceNumber'>: <tmpl_var name='questionText'></div>
|
||||
|
||||
<tmpl_if name='multipleChoice'>
|
||||
<tmpl_if name='maxMoreOne'>
|
||||
|
|
@ -65,8 +65,8 @@
|
|||
</tr>
|
||||
<tr>
|
||||
<tmpl_loop name=answers>
|
||||
<td align="center" width="2em">
|
||||
<span class=answer id="<tmpl_var name='Survey_answerId'>container"></span>
|
||||
<td align="center" width=75px>
|
||||
<span class=scaleanswer id="<tmpl_var name='Survey_answerId'>container"></span>
|
||||
<tmpl_if name='verbatim'>
|
||||
<span><input type=text name='<tmpl_var name='Survey_answerId'>verbatim'></span>
|
||||
</tmpl_if>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue