Toggle menu
862
3.8K
30.2K
279.1K
Catglobe Wiki
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Require only one check for grid question: Difference between revisions

From Catglobe Wiki
No edit summary
Cg loc (talk | contribs)
No edit summary
 
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 03: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

Solution

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

Code

var normalQuestionCheck = questioncheck;

function extendedQuestionCheck()
{
   ErrorMessages.getInstance().clearErrorMessages();//clear old error message
   var valid = false;
   var q_name = "QUESTION." + "GridQuestionLabel";//question's name = "QUESTION." + question label
   var n = $(".grid_inner")[0].rows.length - 1;//number of sub questions

   //check if each answer option for each sub question is checked
   for(var i=0;i<n;i++)
	{
		$("input:checkbox[name='"+q_name+"."+i+"']").each(
			function()
			{
				if($(this).attr("checked"))
					valid = true;				
			}
		);
		if(valid)
		break;
	}
	
   if(!valid) showError(quest.requiredtext);
   return valid;
         
}

function showError(e)
{
   ErrorMessages.getInstance().showErrorMessage(e);
}

questioncheck = extendedQuestionCheck;

Source

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