Require only one check for grid question: Difference between revisions
From Catglobe Wiki
More actions
Created page with '== 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. == …'  |
No edit summary  |
||
| (2 intermediate revisions by one other user not shown) | |||
| 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'''<br> | |||
[[Image:OneCheckRequired. | [[Image:OneCheckRequired.png ]] | ||
== | == 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 28: | Line 32: | ||
} | } | ||
 if(!valid) showError(quest.requiredtext); | |||
 return valid; | |||
      |       | ||
} | } | ||
| Line 35: | Line 39: | ||
function showError(e) | function showError(e) | ||
{ | { | ||
 ErrorMessages.getInstance().showErrorMessage(e); | |||
} | } | ||
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
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)
