Onyx Questionnaire Cookbook

Skip to end of metadata
Go to start of metadata

Overview

This page shows how to create questions in all the available formats, how to add categories to a question, how to group questions, and gives a few other useful techniques for coding your questionnaire.


How to create an exclusive choice question (radio buttons)

An exclusive choice question is a question for which the participant can only choose one category.  Its categories are displayed as radio buttons. See a screenshot of an example here.

First, you create a Section / Page structure in which to add the question:

...or you can add the new question to an existing Page:

Then you add categories to the question:

The categories are displayed in a grid (multiple rows and columns). To see a single-column layout, look here. To see a multiple-column layout, look here.

The default number of rows is 5, but you can set the number of rows as shown below. You do not set the number of columns; it is derived: (Number of categories)/(Number of rows).

How to create a multiple choice question (checkboxes)

A multiple choice question is a question for which the participant can select several categories. The categories are displayed with checkboxes so the participant can select all the categories that apply. See a screenshot of an example here

See also How to make a category an exclusive choice in a multiple choice question.

How to group a list of questions

One way of grouping questions is to make the questions children of a parent question. Then you could configure each child question individually. 

You can also group questions by using an array question. See How to create an array question.

How to create an array question (use the same categories for a group of questions)

An array question includes a number of child questions, and a number of categories. The child questions automatically include the categories of the parent question.  See a screenshot of an array question here

By default, the child questions receive all the categories and configuration of the parent, however the child questions can be configured individually. For example: you can redefine whether one or multiple categories can be selected, what the answer count is, and so on.

You use an array question to group questions if all the questions take the same answers. If you want to group questions that do not all take the same answers, see How to group a list of questions.

How to limit the number of answers to a question

You can specify the minimum and maximum number of answers that a participant can select for a question.  This applies to questions that are not open-answer questions.  

How to make a question optional

Making a question optional is as simple as calling the optional() method on the question builder, as shown below.

You can also specify a default "no-answer" category which will be used to answer any unanswered optional question.  This is done using the noAnswer() method on the category builder.

This means that the question will be automatically answered with this "no-answer" category, if it has been shown to the user but was left unanswered. This is useful if you want to know why the question was not answered. Is it because the user decided not to answer it, or because the question was never presented to him?

How to share categories (througout the questionnaire)

Sharing a category means reusing a category's configuration (and possibly its associated open answers) for different questions anywhere in the questionnaire.  You configure the category first time you add it to one question. Then you can refer to this category by name when you are defining another question. The advantages of sharing categories are: you only to configure the category once, and you only need to localize the text for the category once in the properties file for each interface language (see Localizing the Questionnaire).

To ensure consistency in your shared categories, you can define static variables  for shared category that you require in questionnaire builder class.  When you add a shared category to a question, you use the static variable.

See also How to create an array question (use the same categories for a group of questions).

How to define an alternative name for a category (whether shared or not)

When you add a category to a question, you can provide an alternative name for the category.

Since category names are not unique in a questionnaire, it may be necessary to specify an alternative name for the category for the question to which the category  belongs.

Usually categories are given alphanumerical names for readability. However, some old statistical systems only deal with numerical values, so you can give an alternative name (also called an export name) which can be represented as a numerical value.

How to make a category an exclusive choice in a multiple choice question

Even though a multiple choice question normally allows the participant to select several answers, there are certain categories that, if selected, can be the only selection.  For those properties, you must set the 'escape' property to true. For example:

How to add an open-answer question

An open -answer question is a question that the participant responds to by supplying their own answer rather than by selecting a category. The participant's answer is entered in a field.

You create an open-answer question by adding the OPEN_N category to it. Then you set the DataType, so that the appropriate UI element is used and so that the entry can be validated appropriately.

The possible data types are:

  • DataType.BOOLEAN
  • DataType.DATA
  • DataType.DATE
  • DataType.DECIMAL
  • DataType.INTEGER
  • DataType.TEXT

By default, an open-answer question is optional. To make it required, set the minimum number of answers to 1.

To restrict the size the field used to capture the participant's response to an open-answer question, set the 'size' property.

The participant response field can also be presented as a text area.  This can be done by specifying the number of rows.

How to use multiple fields for an open-answer question

The participant's response to an open-answer question can be captured in several fields. To do this, you add the open-answer question and its category, then you add an open-answer definition (the parent definition) to the category and several child open-answer definitions to the parent definition.

How to validate an open-answer question

A validator can be applied to the response captured for an open-answer question. Two kinds of validator are available:

How to set a condition for displaying a question (also known as a skip pattern)

To control whether or not a question is displayed, you can set a condition on the question.  The condition is defined with one or more DataSource objects.  When you call the setCondition method, you can pass it:

  • The names of questions and categories defined earlier in the your builder class.  DataSource objects will be constructed from these names.  See the first two examples below.
  • A boolean expression that will be evaluated at runtime, and the DataSource objects used in the expression. The DataSource objects are constructed from names and categories defined earlier in your builder class. See the third example below.

At runtime, the DataSource will provide a Data object that will be interpreted as a boolean value (true or false). If the returned Data object is null, the condition is resolved as being false. 

How to set the questions, categories and open answers variable name

Variable names are automatically generated but if they are too long or if a custom name is preferred it is possible to provide one using the setVariableName() method.

Renaming questions

Specifying the variable name of a question:

Automatically Generated Variable Names Custom Variable Names (above code)
ABLE_TO_BALANCE_ON_ONE_FOOT
ABLE_TO_BALANCE_ON_ONE_FOOT.N
ABLE_TO_BALANCE_ON_ONE_FOOT.Y
balance_on_one_foot
balance_on_one_foot.N
balance_on_one_foot.Y
Renaming categories

Specifying the category name:

Automatically Generated Variable Names Custom Variable Names (above code)
STANDING_HEIGHT_CI
STANDING_HEIGHT_CI.NC
STANDING_HEIGHT_CI.SEVERE_SPINE_CONDITION
STANDING_HEIGHT_CI.OTHER
STANDING_HEIGHT_CI
STANDING_HEIGHT_CI.NC
severe_spine_condition
STANDING_HEIGHT_CI.OTHER
Renaming open answer definitions

Specifying the open answer definition name:

Automatically Generated Variable Names Custom Variable Names (above code)
WAIST_HIPS_CI
WAIST_HIPS_CI.NC
WAIST_HIPS_CI.YES_SPECIFY
WAIST_HIPS_CI.YES_SPECIFY.YES_SPECIFY
WAIST_HIPS_CI
WAIST_HIPS_CI.NC
WAIST_HIPS_CI.YES_SPECIFY
waist_hips_ci_reason
Renaming questions in a array of questions

Specifying the variable name of each question in the array of questions.

Automatically Generated Variable Names Custom Variable Names (above code)
ARRAY_OPEN.RED_WINE
ARRAY_OPEN.RED_WINE.WEEK
ARRAY_OPEN.RED_WINE.PNA
ARRAY_OPEN.RED_WINE.DNK
ARRAY_OPEN.WHITE_WINE
ARRAY_OPEN.WHITE_WINE.WEEK
ARRAY_OPEN.WHITE_WINE.PNA
ARRAY_OPEN.WHITE_WINE.DNK
red_wine
red_wine.WEEK
red_wine.PNA
red_wine.DNK
white_wine
white_wine.WEEK
white_wine.PNA
white_wine.DNK
Renaming categories in a array of questions

Specifying the variable name of categories and shared categories. In this case the question has multiple possible answers so it is necessary to explicitly associate the custom category variable with a specific question using the method setVariableName(questionName, variableName).

Automatically Generated Variable Names Custom Variable Names (above code)
ARRAY_OPEN.RED_WINE
ARRAY_OPEN.RED_WINE.WEEK
ARRAY_OPEN.RED_WINE.PNA
ARRAY_OPEN.RED_WINE.DNK
ARRAY_OPEN.WHITE_WINE
ARRAY_OPEN.WHITE_WINE.WEEK
ARRAY_OPEN.WHITE_WINE.PNA
ARRAY_OPEN.WHITE_WINE.DNK
ARRAY_OPEN.RED_WINE
red_wine_week
red_wine_pna
red_wine_dnk
ARRAY_OPEN.WHITE_WINE
white_wine_week
white_wine_pna
white_wine_dnk
Renaming open answer definitions in a array of questions

Specifying the open answer definition name in a joined categories question array:

Automatically Generated Variable Names Custom Variable Names (above code)
ARRAY_OPEN_DS.RED_WINE_DS
ARRAY_OPEN_DS.RED_WINE_DS.WEEK_DS
ARRAY_OPEN_DS.RED_WINE_DS.WEEK_DS.WEEK_QUANTITY
ARRAY_OPEN_DS.RED_WINE_DS.PNA
ARRAY_OPEN_DS.RED_WINE_DS.DNK
ARRAY_OPEN_DS.WHITE_WINE_DS
ARRAY_OPEN_DS.WHITE_WINE_DS.WEEK_DS
ARRAY_OPEN_DS.WHITE_WINE_DS.WEEK_DS.WEEK_QUANTITY
ARRAY_OPEN_DS.WHITE_WINE_DS.PNA
ARRAY_OPEN_DS.WHITE_WINE_DS.DNK
ARRAY_OPEN_DS.RED_WINE_DS
ARRAY_OPEN_DS.RED_WINE_DS.WEEK_DS
red_wine_week_quantity
ARRAY_OPEN_DS.RED_WINE_DS.PNA
ARRAY_OPEN_DS.RED_WINE_DS.DNK
ARRAY_OPEN_DS.WHITE_WINE_DS
ARRAY_OPEN_DS.WHITE_WINE_DS.WEEK_DS
white_wine_week_quantity
ARRAY_OPEN_DS.WHITE_WINE_DS.PNA
ARRAY_OPEN_DS.WHITE_WINE_DS.DNK
Search Onyx Documentation
Labels:
None
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.