Difference between revisions of "Require only one check for grid question"
Line 28: | Line 28: | ||
} | } | ||
− | + | if(!valid) showError(quest.requiredtext); | |
− | + | return valid; | |
} | } | ||
Line 35: | Line 35: | ||
function showError(e) | function showError(e) | ||
{ | { | ||
− | + | ErrorMessages.getInstance().showErrorMessage(e); | |
} | } | ||
questioncheck = extendedQuestionCheck; | questioncheck = extendedQuestionCheck; | ||
</source> | </source> |
Revision as of 04:44, 8 December 2009
Challenge
Normally, the grid question require one answer for each sub question to navigate to next question. Now, we want it require only one check for the whole grid.
Example
Script
1 var normalQuestionCheck = questioncheck;
2
3 function extendedQuestionCheck()
4 {
5 ErrorMessages.getInstance().clearErrorMessages();//clear old error message
6 var valid = false;
7 var q_name = "QUESTION." + "GridQuestionLabel";//question's name = "QUESTION." + question label
8 var n = $(".grid_inner")[0].rows.length - 1;//number of sub questions
9
10 //check if each answer option for each sub question is checked
11 for(var i=0;i<n;i++)
12 {
13 $("input:checkbox[name='"+q_name+"."+i+"']").each(
14 function()
15 {
16 if($(this).attr("checked"))
17 valid = true;
18 }
19 );
20 if(valid)
21 break;
22 }
23
24 if(!valid) showError(quest.requiredtext);
25 return valid;
26
27 }
28
29 function showError(e)
30 {
31 ErrorMessages.getInstance().showErrorMessage(e);
32 }
33
34 questioncheck = extendedQuestionCheck;