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

From Catglobe Wiki

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)