Add text before answer option of single question

From Catglobe Wiki
Revision as of 04:27, 17 October 2013 by Nguyentrantri (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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