Difference between revisions of "Add text before answer option of single question"

From Catglobe Wiki
Jump to: navigation, search
(New page: == Challenge == In order to add text before answer option of single question As a questionnaire creator I want to add text before answer option of single question '''Example''' I have...)
 
 
(17 intermediate revisions by 3 users not shown)
Line 11: Line 11:
 
I have a single question.
 
I have a single question.
  
[[Image: SingleAddtext.jpg]]
+
{| border="0"
 +
|-
 +
| align="center" | [[File:OneColumnBefore.JPG|none]]<br/>
 +
| [[File:MultiColumnBefore.JPG|none]]<br/>
 +
|}
  
I want to add an text before answer option like this image
+
<br/>I want to add an text before answer option like this image
  
[[Image: SingleAddtext2.jpg]]
+
{|
 +
|-
 +
| align="center" | [[File:OneColumnAfter.jpg|none]]<br/>
 +
| [[File:MultiColumnAfter.jpg|none]]<br/>
 +
|}
  
== Solution ==
+
== Solution ==
  
Find the answer option in single question , and add new text before it .
+
*Add a Single question to Questionaire editor
 +
*Go to menu Properties -> Question scripts -> Java script tab -> Input script
  
== Code  ==
+
[[File:AddTextBeforeAOOfSingleQuestion.jpg|none]]
  
<source lang="javascript" line="1">
+
== Code ==
quest.insertTextBefore = function(valueOfAnswerOption, text)
+
 
 +
<source lang="javascript">
 +
quest.insertTextBefore = function(aoIndex, text)
 
{
 
{
var inp = $(".option_table").find("input[value='"+valueOfAnswerOption+"']");
+
var that = this;
if(inp.length <= 0)
+
$(".option_row").each(
return;
+
function(i)
if(this.autoarrangeansweroptions != false && cols > 1)
+
{
$("<tr><td class=\"answer_option_cell\" colspan=\"3\">"+text+"</td></tr>").insertBefore($(inp.parent().parent()));
+
if (i == aoIndex)
else
+
{
$("<tr><td class=\"answer_option_cell\">"+text+"</td></tr>").insertBefore($(inp.parent().parent().parent().parent().parent().parent()));
+
var tr = $("<tr>").addClass("customized_text")
 +
.append($("<td>").text(text).attr("colSpan",that.cols));
 +
$(this).before(tr);
 +
}
 +
}
 +
);
 +
 
 
}
 
}
  
 
quest.onInit = function()
 
quest.onInit = function()
 
{
 
{
this.insertTextBefore(8, "hello there!!");
+
var text = "My Text";
        this.insertTextBefore(5, "hello there 2!!");
+
this.insertTextBefore(2, text);
 +
}
 +
</source>
 +
 
 +
== Question stylesheet ==
 +
 
 +
<source lang="css">
 +
.customized_text
 +
{
 +
background-color:white;
 
}
 
}
 
</source>
 
</source>
 +
 +
== Source ==
 +
 +
Questionnaire Resource Id on cg site: 159730
 +
 +
Question: Q_OS_Single_AddTextBeforeAO

Latest revision as of 04:27, 17 October 2013

Challenge

In order to add text before answer option of single question

As a questionnaire creator

I want to add text before answer option of single question

Example

I have a single question.

OneColumnBefore.JPG

MultiColumnBefore.JPG


I want to add an text before answer option like this image

OneColumnAfter.jpg

MultiColumnAfter.jpg

Solution

  • Add a Single question to Questionaire editor
  • Go to menu Properties -> Question scripts -> Java script tab -> Input script
AddTextBeforeAOOfSingleQuestion.jpg

Code

quest.insertTextBefore = function(aoIndex, text)
{
 var that = this;
 $(".option_row").each(
 function(i)
 {
 if (i == aoIndex)
 {
 var tr = $("<tr>").addClass("customized_text")
 .append($("<td>").text(text).attr("colSpan",that.cols)); 
 $(this).before(tr);
 }
 }
 );

}

quest.onInit = function()
{
 var text = "My Text";
 this.insertTextBefore(2, text);
}

Question stylesheet

.customized_text
{
 background-color:white;
}

Source

Questionnaire Resource Id on cg site: 159730

Question: Q_OS_Single_AddTextBeforeAO