Difference between revisions of "Show open textbox in a grid question"

From Catglobe Wiki
Jump to: navigation, search
m (Introduction)
(Solution)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== Introduction ==
+
== Challenge  ==
  
In order to let the respondent specify an open text for Other option<br> As a questionnaire creator<br> I want to show a textbox next to "Other" text in a grid question<br> <br> '''Example'''<br> [[Image:Show open text.png]]  
+
In order to let the respondent specify an open text for Other option<br> As a questionnaire creator<br> I want to show a textbox next to "Other" text in a grid question<br> <br> '''Example'''<br> [[Image:Openinsingrid.png]]
  
 
== Solution ==
 
== Solution ==
  
Assuming that I have a single grid question labeled Q1, and I need to show the open text box in 3rd sub question (0-index).
+
*Assuming that I have a single grid question labeled Q1, and I need to show the open text box in 3rd sub question (0-index)
  
Create a dummy text question labeled Q1_Other
+
*Make the "Other" sub question NOT required
  
 +
*Create a dummy text question labeled Q1_Other
 +
 +
== Code  ==
 
Add a piece of javascript to Q1
 
Add a piece of javascript to Q1
  
<br>
+
<source lang=javascript>
<source language=javascript>
 
 
var errorMessage = "Please specify the open text";
 
var errorMessage = "Please specify the open text";
 
var subQuestionIndex = 3;//0-based
 
var subQuestionIndex = 3;//0-based
Line 38: Line 40:
 
}
 
}
 
</source>
 
</source>
 +
 +
Add a CGScript to Q1_Other to remove double quotes
 +
<source lang=csharp>
 +
if (Q1_Other == empty)
 +
return;
 +
Q1_Other = stringReplace(Q1_Other, "\"", "'");
 +
</source>
 +
== Source  ==
 +
Questionnaire Resource Id on cg.catglobe.com site: 164079 (Question: Q6_Show_open_textbox_in_a_grid_question & D_Q6_Show_open_textbox_in_a_grid_question_Other)

Latest revision as of 11:07, 3 February 2012

Challenge

In order to let the respondent specify an open text for Other option
As a questionnaire creator
I want to show a textbox next to "Other" text in a grid question

Example
Openinsingrid.png

Solution

  • Assuming that I have a single grid question labeled Q1, and I need to show the open text box in 3rd sub question (0-index)
  • Make the "Other" sub question NOT required
  • Create a dummy text question labeled Q1_Other

Code

Add a piece of javascript to Q1

var errorMessage = "Please specify the open text";
var subQuestionIndex = 3;//0-based

quest.onInit = function()
{
   $("#grid_subquestion_text_"+ (subQuestionIndex+1)).append($("<input name='QUESTION.Q1_Other'>").val("{{Q1_Other}}"));
}

var oldCheck = questioncheck;
questioncheck = function()
{
   if (!oldCheck())
   return false;
   
   if ($("input:radio[name='QUESTION.Q1."+ subQuestionIndex + "'][checked=true]").length != 0)
   {
      if ($("input[name='QUESTION.Q1_Other']").val() == "")
      {      
         ErrorMessages.getInstance().showErrorMessage(errorMessage);
         return false;
      }
   }
   return true;
}

Add a CGScript to Q1_Other to remove double quotes

if (Q1_Other == empty)
return;
Q1_Other = stringReplace(Q1_Other, "\"", "'");

Source

Questionnaire Resource Id on cg.catglobe.com site: 164079 (Question: Q6_Show_open_textbox_in_a_grid_question & D_Q6_Show_open_textbox_in_a_grid_question_Other)