Difference between revisions of "Questionnaire - Javascript Fun Tips"

From Catglobe Wiki
Jump to: navigation, search
(Examples)
 
(45 intermediate revisions by 11 users not shown)
Line 1: Line 1:
== Basic Hints ==
+
'''[[Basic Hints|Basic Hints]]'''
  
Questionnaire viewer is implemented in a way that you can add javascript to manipulate the way your questions are displayed.
+
'''[[Show more than one questions in the same page]]'''
  
jQuery is already included in the viewer, thanks to what javascript has even more powerful effect! (read more about jquery here: [http://jquery.com/ http://jquery.com/])
+
'''[[Add answer options of the close questions to the open questions]]'''
  
Javascript is a property on both question and questionnaire levels, which means that you can add javascript for each question or for the whole questionnaire.
+
'''[[Validate the questions by using the questioncheck() function]]'''
  
The most important features are:
+
'''[[Show a text grid and a single question in the same page|Show a text grid question and a single question in the same page]]'''
  
*quest: the current question's object
+
'''[[Show more than one singe grid in the same page|Show more than one single grid in the same page]]'''
*questioncheck: the function called before going Next
 
  
=== quest  ===
+
'''[[Show more than one singe question in the same page|Show more than one single question in the same page]]'''
  
There are several important properties in quest object:
+
'''[[Show single questions as dropdown lists in their own pages]]'''
  
*quest.questions: array of sub questions
+
'''[[Insert a TextGrid question into a SingleGrid Question]]'''
*quest.options: array of answer options
 
*quest.setQuestions(Array subQuestions): assign an array of question objects to the sub question list of the current question
 
*quest.setOptions(Array options): assign an array of options to the answer option list of the current question
 
*quest.setAnswer(string value): assign a value to the question  
 
*quest.getHTML(): returns the HTML which will be rendered to display the question
 
*quest.onInit(): called right after loading the question
 
*quest.rotateAnswerOptions(startIndex, endIndex, rotateIndex): rotate answer options in a range specified by startIndex and endIndex, the first item in the range will be rotateIndex
 
*quest.rotateSubQuestions(startIndex, endIndex, rotateIndex): rotate sub questions in a range specified by startIndex and endIndex, the first item in the range will be rotateIndex
 
*quest.randomizeAnswerOptions(randomSeed, startIndex, endIndex): randomize answer options in a range specified by startIndex and endIndex, the order is unique for each randomSeed
 
*quest.randomizeSubQuestions(randomSeed, startIndex, endIndex):randomize sub questions in a range specified by startIndex and endIndex, the order is unique for each randomSeed<br>
 
  
=== questioncheck()  ===
+
'''[[Some special questions on COOP Site]]'''
  
We need to override this function to get rid of the default question check supported by the questionnaire viewer, it is a must when showing more than one questions in the same page. The function returns true when there is nothing wrong and false otherwise.
+
----
  
There is an object which should be used to display errors: ErrorMessages.
+
<br/>[[Showing Answer Option in tab]]
  
*ErrorMessages.getInstance().clearErrorMessages(): clear all existing error messages
+
[[Rotate answer options/sub questions]]
*ErrorMessages.getInstance().showErrorMessage(msg): show an error message
 
  
==Technical tips==
+
[[Randomize answer options/sub questions]]
===Include an external script library===
 
In case we want to use external javascript libraries hosted on external servers (like google), we need to include the library link to the question script.<br/>
 
A simple method of doing so is using jquery's getScript method (http://docs.jquery.com/Ajax/jQuery.getScript#urlcallback)<br/>
 
<b>Example:</b><br/>
 
<source lang = javascript>
 
$.getScript("http://ui.jquery.com/testing/ui/ui.datepicker.js", function()
 
      {
 
//the library is now ready to use
 
}
 
);
 
</source>
 
  
===Edit stylesheet===
+
[[Drag and drop answer option values]]
The easiest way is to use Firefox with Web Developer Add-on (http://chrispederick.com/work/web-developer)<br/>
 
  
[[Image:Web_developer.png]]
+
[[Change Impsys mages]]
  
== Examples  ==
+
[[Add an extra row before a sub question in a grid]]
[[Showing Answer Option in tab]]
 
  
[[Rotate answer options/sub questions]]  
+
[[Hide sub question text column in a grid question]]
  
[[Randomize answer options/sub questions]]  
+
[[Change stylesheet of an answer option column in a single grid question]]
  
[[Drag and drop answer option values]]  
+
[[Add an extra column before an answer option column in single grid question]]
  
[[Change Impsys mages]]  
+
[[Both horizontal and vertical single grid]]
  
[[Add an extra row before a sub question in a grid]]  
+
[[Disable sub questions in text grids]]
  
[[Hide sub question text column in a grid question]]  
+
[[Number grid]]
  
[[Show a text grid and a single question in the same page|Show a text grid question and a single question in the same page]]  
+
[[Close to URL]]
  
[[Change stylesheet of an answer option column in a single grid question]]  
+
[[Double columns in text grids]]
  
[[Add an extra column before an answer option column in single grid question]]  
+
[[Count down with invisible counter]]
  
[[Both horizontal and vertical single grid]]  
+
[[Fold in/out texts in question text]]
 +
 
 +
[[Force email address]]
 +
 
 +
[[Force number of characters]]
 +
 
 +
[[Change text box size]]
 +
 
 +
[[Set focus on question text in the top]]
 +
 
 +
[[Maximum text length]]
 +
 
 +
[[Next button count down]]
  
[[Disable sub questions in text grids]]  
+
[[Mark answer option with keyboard]]
  
[[Number grid]]  
+
[[Show flash movies on questionnaire viewer|Play a list of movies in questionnaire]] <!--[[Play a commercial and automatically go next when it is over in questionnaire]] : doesnt not work -->[[Show a single question as a dropdown list inside another text grid question]]
 +
 
 +
[[Hide Next button in n seconds]]
  
[[Close to URL]]  
+
[[Show datepicker in text/text grid questions]]
  
[[Double columns in text grids]]  
+
[[Show column header in text grid question]]
  
[[Count down with invisible counter]]  
+
[[Prioritize sub questions in a text grid question]]
  
[[Fold in/out texts in question text]]
+
[[Align min/max texts in scale grid questions]]
 +
 
 +
[[Add text before answer option of single question]]
 +
 
 +
[[Show language selector page]]
  
[[Force email address]]  
+
[[Reverse single grid between sub questions and answer options]]
  
[[Force number of characters]]  
+
[[Script for making a text grid numerical summing to a specific value]]
  
[[Change text box size]]  
+
[[Convert closed question TextBox into TextArea]]
  
[[Set focus on question text in the top]]  
+
[[Validate email specified as an open text of a single question]]
  
[[Maximum text length]]  
+
[[Require only one check for grid question]]
  
[[Next button count down]]  
+
[[Change non-multi option in Multi question to Radio button]]
  
[[Mark answer option with keyboard]]  
+
[[Make whole cell clickable in single and multi grids]]
  
[[Show flash movies on questionnaire viewer|Play a list of movies in questionnaire]]  
+
[[AutoSum numerical text grid]]
  
[[Play a commercial and automatically go next when it is over in questionnaire]]  
+
[[Show open textbox in a grid question]]
  
[[Show a single question as a dropdown list inside another text grid question]]  
+
[[Change progress bar images of questionnaire]]
  
[[Hide Next button in n seconds]]
+
[[Add CKEditor to an Open question]]
  
[[Show datepicker in text/text grid questions]]
+
[[Upload images in questionnaire]]
  
[[Show column header in text grid question]]
+
[[Check whether values of open parts of a close question are positive numbers or not]]
  
[[Prioritize sub questions in a text grid question]]
+
[[Reverse the position of the subquestion texts with their textboxes in the text-grid question]]
  
[[Align min/max texts in scale grid questions]]
+
[[Show multi, single question in new style]]
  
[[Add text before answer option of single question]]
+
[[Get parameters from answer sheet link]]

Latest revision as of 14:55, 26 May 2015

Basic Hints

Show more than one questions in the same page

Add answer options of the close questions to the open questions

Validate the questions by using the questioncheck() function

Show a text grid question and a single question in the same page

Show more than one single grid in the same page

Show more than one single question in the same page

Show single questions as dropdown lists in their own pages

Insert a TextGrid question into a SingleGrid Question

Some special questions on COOP Site



Showing Answer Option in tab

Rotate answer options/sub questions

Randomize answer options/sub questions

Drag and drop answer option values

Change Impsys mages

Add an extra row before a sub question in a grid

Hide sub question text column in a grid question

Change stylesheet of an answer option column in a single grid question

Add an extra column before an answer option column in single grid question

Both horizontal and vertical single grid

Disable sub questions in text grids

Number grid

Close to URL

Double columns in text grids

Count down with invisible counter

Fold in/out texts in question text

Force email address

Force number of characters

Change text box size

Set focus on question text in the top

Maximum text length

Next button count down

Mark answer option with keyboard

Play a list of movies in questionnaire Show a single question as a dropdown list inside another text grid question

Hide Next button in n seconds

Show datepicker in text/text grid questions

Show column header in text grid question

Prioritize sub questions in a text grid question

Align min/max texts in scale grid questions

Add text before answer option of single question

Show language selector page

Reverse single grid between sub questions and answer options

Script for making a text grid numerical summing to a specific value

Convert closed question TextBox into TextArea

Validate email specified as an open text of a single question

Require only one check for grid question

Change non-multi option in Multi question to Radio button

Make whole cell clickable in single and multi grids

AutoSum numerical text grid

Show open textbox in a grid question

Change progress bar images of questionnaire

Add CKEditor to an Open question

Upload images in questionnaire

Check whether values of open parts of a close question are positive numbers or not

Reverse the position of the subquestion texts with their textboxes in the text-grid question

Show multi, single question in new style

Get parameters from answer sheet link