Represents Question object.
Properties:
- OpenEnded = 1,
- SingleAnswer = 3,
- MultipleAnswers = 4,
- SingleSelectCombo = 5,
- MatrixSingle = 6,
- MatrixMultiple = 7,
- Rating = 8,
- Ranking = 10,
- ConstantSum = 12,
- ContinuousSum = 13,
- RatingSlider = 15,
- SemanticDifferential = 16,
- MediaQuestion = 17,
- Instructions = 18
Name | Type | Description |
---|---|---|
questionType | Number | Indicates current question type. It can be on of the following: |
code | String | Questionnaire item code specified by the questionnaire author. It must be unique within the questionnaire. |
indexer | String | Returns Alternative item by its unique code. If the code is not assigned explicitly than Alternative order index can be used for that purpose. |
alternatives | Array.<Alternative> | Array of all Alternative items sorted by inital order (respect randomization). |
name | String | Questionnaire item display text (question text or section name). |
isRequired | Boolean | Boolean property that indicates whether the question must have answers. |
alternativeLayoutCols | Number | Sets number of columns for alternatives rendering. |
comments | String | Sets comments after the question |
rcaption1 | String | Sets caption for first label in Rating Slider question |
rcaption2 | String | Sets caption for second label in Rating Slider question |
rcaption3 | String | Sets caption for third label in Rating Slider question |
showLabels | Boolean | Indicates whether to show or not labels for Rating Slider question |
randomizeAlternatives | Boolean | Indicates whether answer options are to be randomized |
randomizeColumns | Boolean | Indicates whether column answer options inside matrix question are to be randomized |
maxRankingOptions | Number | Sets maximum number of answers to rank for Ranking question |
constantSumTotal | Number | Sets constant sum total for Constant sum question |
isMatrix | Boolean | Checks whether the question is matrix or not |
limitTimeout | Number | Sets maximum show time for Media question |
mediaPath | String | Sets path of media file for question |
Examples
//hide all rating questions
for (var i = 0; i < q.questions.length; i++) {
var question = q.questions[i];
if (question.questionType==8||question.questionType==15) {
question.hide();
}
//check for the specific question
if (q.items[2].code=='q1') {
//do something
}
//force the question to be required
q['q5'].isRequired = true;
//Render alternatives in two columns
q['q5'].alternativeLayoutCols = 2;
// get answer name of question q2 and set it as comments for question q3
var answer_text = q.q2.answerText();
q.q3.comments = answer_text;
// set showLabel value for Rating Slider question in true
q.q5.showLabels = true;
// set caption for first label
q.q5.rcaption1 = "First Caption";
Extends
- QuestItem
Methods
(inner)all()→ {Boolean}
- Check if all of the specified values are selected.
Returns true if all of the specified values are selected and false otherwise.
Parameters:
Type Description String | Array Array of values to test. Returns:
- Type
- Boolean
Example
//check if all alternatives with specified codes //are selected in multiple or single question q['q1'].all(['a1.1','a1.2','a1.3']); //check if question has all responses with specified text q['q1'].all(['some text','some text value']);
(inner)answerText()→ {String}
- Returns the selected alternative name.
If few alternatives were selected will return the name of first alternative.
Returns:
- Type
- String
(inner)answerTexts()→ {Array.<String>}
- Returns the selected alternatives names.
Returns:
- Type
- Array.<String>
(inner)any()→ {Boolean}
- Check if any of the specified values are selected.
Returns true if any of the specified values are selected and false otherwise.
Parameters:
Type Description String | Array Array of values to test. Returns:
- Type
- Boolean
Example
//check if any of the alternatives with specified //codes is selected in multiple or single question q['q1'].any(['a1.1','a1.2','a1.3']); //check if question has a response with specified text q['q1'].any(['some text','some text value']);
(inner)filter(from)
- Shows only alternatives which were chosen in previous question
Parameters:
Name Type Description from
String Code of previous question. Example
// Suppose we have two questions with the same alternatives codes. // We will show in question q3 only alternatives which were choosen in question q2 q.q3.filter('q2');
(inner)filtern(from)
- Shows only alternatives which were not chosen in previous question
Parameters:
Name Type Description from
String Code of previous question. Example
// Suppose we have two questions with the same alternatives codes. // We will show in question q3 only alternatives which were not choosen in question q2 q.q3.filtern('q2');
(inner)get()→ {Array.<Answer>}
- Returns array of respondent's answers.
- See:
- Answer
Returns:
- Type
- Array.<Answer>
Examples
// Suppose we want to do some operation if Alternative with code 'a1' has been chosen // then we have to do next // in case if you expect single answer in array if (q.q1.get()=='a1') { //do something } // in case if you expect answers from Multiple question if (q.q1.get().contains('a1')) { //do something }
// Suppose we want to do some operation if Alternative with numeric code 1 has been chosen // then we have to do next // in case if you expect single answer in array if (q.q1.get()==1) { //do something } // in case if you expect answers from Multiple question if (q.q1.get().contains(1)) { //do something }
(inner)getAlternatives()→ {Array.<Alternative>}
- Returns all question alternatives
Returns:
- Type
- Array.<Alternative>
(inner)getPrimaryAlternatives()→ {Array.<Alternative>}
- Returns primary question alternatives
Returns:
- Type
- Array.<Alternative>
Example
// Suppose question "q2" has three alternatives (Alt1,Alt2,Alt3) and Alt1 has been checked as "other" q.q2. getPrimaryAlternatives(); // will return [Al2, Alt3]
(inner)hide()
- Hide question.
Example
//hide q1 question q.q1.hide();
(inner)insertAfter(code)
- Move selected question after the target question.
Parameters:
Name Type Description code
String question code Example
//insert question with code "q5" after question with code "q2" q['q5'].insertAfter('q2'); //or q['q5'].insertAfter(q['q2']);
(inner)insertBefore(code)
- Move selected question before the target question.
Parameters:
Name Type Description code
String question code Example
//insert question with code "q5" before question with code "q2" q['q5'].insertBefore('q2'); //or q['q5'].insertBefore(q['q2']);
(inner)isVisible()→ {Boolean}
- Checks if specific question is visible.
Returns:
- Type
- Boolean
Example
//screen out respondent if question q2 is not visible if (!q.q2.isVisible()){ q.screenOutRespondent(); }
(inner)jump()
- Jump to the specified element.
Skip all questions until the selected questionnaire item.
Example
//navigate to the item with code "q1" q['q1'].jump();
(inner)none()→ {Boolean}
- Check if none of the specified values are selected.
Returns true if none of the specified values are selected and false otherwise.
Parameters:
Type Description String | Array Array of values to test. Returns:
- Type
- Boolean
Example
//check if none of the alternatives with specified codes //is selected in multiple or single question q['q1'].none(['a1.1','a1.2','a1.3']); //check if question has no responses with specified text q['q1'].none(['some text','some text value']);
(inner)onAnswer(handler)
- Attaches handler (function) to the question onAnswer event.
Parameters:
Name Type Description handler
function Attached handler Example
Attach "someHandler" to the question "q1" onAnswer method var someHandler = function(value) { //do some work }; q.q1.onAnswer(someHandler);
(inner)onRender(handler)
- Attaches handler (function) to the question onRender event.
Parameters:
Name Type Description handler
function Attached handler Example
Attach "someHandler" to the question "q1" onRender method var someHandler = function(value) { //do some work }; q.q1.onRender(someHandler);
(inner)onValidate(handler)
- Attaches handler (function) to the question onValidate event.
Parameters:
Name Type Description handler
function Attached handler Example
Attach "someHandler" to the question "q1" onValidate method var someHandler = function(value) { //do some work }; q.q1.onValidate(someHandler);
(inner)set(code, value)
- Sets answer for question.
Parameters:
Name Type Description code
String | Array.<String> Code of alternative value
* Settable value of alternative Example
// set answer a1 (alternative with code "a1") for Single Answer question q.q2.set('a1', 1); // set answers a1 and a3 ((alternatives with code "a1" and "a3")) for Multi Answer question q.q2.set(['a1','a3']); // set value "Answer string" for alternative with code a1 for Open Ended question q.q2.set('a1', "Answer string"); // set value 4 for alternative with code a1 for Rating question q.q2.set('a1', 4);
(inner)show()
- Display question.
Example
//show q1 question q.q1.show();
(inner)shuffle(from, transposed)
- Shuffle question alternatives in order of source question.
Parameters:
Name Type Description from
String code of source question transposed
Boolean Used only for matrix questions. Indicates whether the source matrix is transposed or not. Example
// shuffle question q3 alternatives in order of question q2 alternatives q.q3.shuffle('q2');
(inner)toggle()
- Display or hide (changes visibilty) the question.
If question is initially displayed, it will be hidden; if hidden, it will be shown.
Example
//change visibility to the opposite of the q1 question q.q1.toggle();