Represents Questionnaire item object. It may be a question, a section or a pagebreak.
Properties:
- Question = 0 (question object)
- Section = 1 (section declaration object used to group questions)
- PageBreak = 2 (pagebreak declaration object, indicates the end of the page)
Name | Type | Description |
---|---|---|
questItemType | Number | Indicates current questionnaire item type. It can be one of the following: |
code | String | Questionnaire item code specified by the questionnaire author. It must be unique within the questionnaire. |
name | String | Questionnaire item display text (question text or section name). |
defaultName | String | Questionnaire item default display text (question text or section name). |
hideName | Boolean | Indicates whether to hide section name. |
Examples
//hide all sections
for (var i = 0; i < q.items.length; i++) {
//check if item is section
if (q.items[i].questItemType == 1) {
q.items[i].hide();
}
}
//check for the specific question
if (q.items[2].code=='q1') {
//do something
}
Methods
(inner)bind(eventType, handler)
- Binds event handler with question event.
Parameters:
Name Type Description eventType
String Event name to bind List of all available event types:
- "answer" - event is rised when respondent answers question (clicks on the alternative)
- "validate" - event is rised before the data is processed (respondent clicks "next" button)
handler
function Handler to execute when the specified event is raised. Example
// bind "answer" event handler to all questions for (var i = 0; i < q.items.length; i++) { //check if item is question if (q.items[i].questItemType == 0) { q.items[i].bind('answer',function(value){ // do something }); } }
(inner)getSection()→ {QuestItem}
- Gets parent section.
Returns:
- Type
- QuestItem
Example
//get parent section by question code var perntSection = q['q1'].getSection();
(inner)getSectionItems()→ {Array.<QuestItem>}
- Returns all items for current section
Returns:
- Type
- Array.<QuestItem>
(inner)hide()
- Hide a questionnaire item (question or section).
Example
//hide selected item q['q1'].hide();
(inner)insertAfter(code)
- Move selected item after the target item.
Parameters:
Name Type Description code
String item code Example
//insert item with code "q5" after item with code "q2" q['q5'].insertAfter('q2'); //or q['q5'].insertAfter(q['q2']);
(inner)insertBefore(code)
- Move selected item before the target item.
Parameters:
Name Type Description code
String item code Example
//insert item with code "q5" before item with code "q2" q['q5'].insertBefore('q2'); //or q['q5'].insertBefore(q['q2']);
(inner)isVisible()→ {Boolean}
- Checks if specific item is visible.
Returns:
- Type
- Boolean
Example
//screen out respondent if specific section is not visible if (!q['section1'].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)refresh()
- Refresh item visual representation.
Redraw item and restores its initial visual state.
Example
//turn on multiline editors for the open ended question q['q1'].openEndedEsse=true; q['q1'].refresh(); //update visual state
(inner)show()
- Display a questionnaire item (question or section).
Example
//show selected item q['q1'].show();
(inner)toggle()
- Display or hide (changes visibilty) the matched elements.
If the item is initially displayed, it will be hidden; if hidden, it will be shown.
Example
//change visibility to the opposite of the selected item q['q1'].toggle();
(inner)trigger(eventType, eventData)
- Notify event handlers about event happened
Parameters:
Name Type Description eventType
String Event name to trigger. eventData
* Event data. Example
//define some function handler and notify handler about event happened var someHandler = function(value) { if (value=='a1'){ // do somthing } }; //bind handler to the "answer" event q['q1'].bind('answer',someHandler); //generate answer event q['q1'].trigger('answer','a1');
(inner)unbind(eventType, handler)
- Unbind the previously attached handler from an event.
Parameters:
Name Type Description eventType
String Event name to unbind. handler
function Attached handler. - See:
- bind
Example
//define some function handler var someHandler = function(value) { // check if value contains 'a1' if (value.contains('a1')) { // do somthing } }; //bind handler to the "answer" event q['q1'].bind('answer',someHandler); //unbind handler q['q1'].unbind('answer',someHandler);