Difference between revisions of "Require only one check for grid question"

From Catglobe Wiki
Jump to: navigation, search
 
Line 1: Line 1:
 
== Challenge ==  
 
== 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.
+
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.<br>
== Example ==
+
'''Example'''<br>
 
[[Image:OneCheckRequired.png ]]
 
[[Image:OneCheckRequired.png ]]
== Script ==  
+
== Solution ==
 +
*Create a grid question
 +
*Add the below script to that question
 +
 
 +
== Code ==  
 
<source lang="javascript" line="1">
 
<source lang="javascript" line="1">
 
var normalQuestionCheck = questioncheck;
 
var normalQuestionCheck = questioncheck;
Line 40: Line 44:
 
questioncheck = extendedQuestionCheck;
 
questioncheck = extendedQuestionCheck;
 
</source>
 
</source>
 +
== Source ==
 +
Questionnaire Resource Id on cg.catglobe.com site: 164079 (Question: Q9_Require_only_one_check_for_grid_question)

Latest revision as of 04:08, 6 February 2012

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
OneCheckRequired.png

Solution

  • Create a grid question
  • Add the below script to that question

Code

 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;

Source

Questionnaire Resource Id on cg.catglobe.com site: 164079 (Question: Q9_Require_only_one_check_for_grid_question)