preignition/program-user-docs
accessiblesurveys
  • TRAINING COURSE
    • Introduction
    • Session 1- Creating a new survey
    • Session 2- Adding accessibility options to a Form
    • Session 3- Translating a Form into different languages
    • Session 4- Sharing your survey using the Survey Editor
    • Session 5- Analysing your survey responses and exporting your survey data
  • TUTORIALS
    • Introduction to creating a new survey
    • Introduction editing a form
    • Introduction to testing a form
    • Introduction to publishing a form
    • Introduction to Easy Read
    • Introduction to Sign Language
    • Introduction to form logic
    • Introduction to the Customer Portal
  • GUIDANCE NOTES
    • Survey App
      • Creating a new survey
      • Form Editor
        • Structuring a form
        • Adding questions to a form
          • Text based questions
          • Choice based questions
          • Rating, Slider, Order and Range questions
          • Media based questions
          • Introduction to free text fields
        • Testing a form
        • Publishing a form
        • Introduction to form logic
        • Advanced form logic
        • Using tooltips
        • Using Markdown
        • Adding an accessibility menu
        • Form Behaviour
        • Image Library
        • Easy Read
        • Sign Language
        • Translate forms
        • Using import/ export to translate forms
        • Access rights for forms
        • Sharing options across multiple questions
      • Survey Editor
        • Editing a survey
        • Distributing your survey
        • Survey respondent accounts
        • Redirection after completing survey
        • Language settings for surveys
        • Creating alias survey links
        • Survey batches
        • Presenting surveys
        • Survey access rights
        • Survey terms- advanced
        • Publishing surveys
      • Analytics
        • Introduction to survey analytics
        • Exporting Survey Data
    • Customer Portal
      • Portal
        • Profile
        • Subscription
      • Team
      • My Profile
      • Users
      • Using labels
  • FAQ
    • Data privacy and security
      • Why and how do we collect data?
      • How do we protect data?
      • What is GDPR?
      • What rights do individuals have under GDPR?
      • What obligations do controllers have under GDPR?
      • What obligations do processors have under GDPR?
      • Where is data stored?
      • How can I ensure that my surveys GDPR compliant?
      • How to Write GDPR-proof Privacy Policy for your Surveys
    • What is the best image size, ratio and format?
    • How to use free text
      • Convenient Class for Accessible Surveys Free Text Field
      • CSS tokens available in Markdown Free Text
      • Web-components available in Markdown Free Text
      • Accessibility Modes
    • FAQ about the Form Editor
      • How do I resolve warnings when publishing a form?
      • How can I get feedback about my survey?
    • Guide to producing Accessible Surveys
      • Producing your survey in Plain Language or Easy to Read
      • Producing your survey in sign languages
    • FAQ about survey data and analytics
      • How do I ensure that the data in my CSV file is properly formatted?
  • Release Notes
    • Form Builder
      • import/export
      • Section Container
    • Process Builder
    • Reporting
    • Survey
  • API
    • survey
    • member
Powered by GitBook
On this page
  • Comparisons
  • Worked example
  • Binary Operators
  • Worked example
  • in operator
  • Worked example
  • Ternary operator
  • Worked example of the ternary operator
  • Additional example of the ternary operator
  • Parentheses
  • Custom Transforms
  • Using 'Length' to customise the number of checkbox options selected
  • Using 'Length' to customise the number of order question items to be ordered
  1. GUIDANCE NOTES
  2. Survey App
  3. Form Editor

Advanced form logic

This page provides guidance for applying advanced form logic

PreviousIntroduction to form logicNextUsing tooltips

Last updated 9 months ago

The logic feature is extremely powerful and there are almost limitless possibilities to what expressions can be written and applied to your form. This guidance note introduces some of the main logic options available and gives practical examples of how they can be applied.

Comparisons

The following comparison operators are available

Comparison
Symbol

Equal

==

Not equal

!=

Greater than

>

Greater than or equal

>=

Less than

<

Less than or equal

<=

Element in array or string

in

Worked example

This is an example of the !( > ) symbol being used to show or hide pages based on a respondent's age.

In this example the the page 'Food Preferences' is hidden if a respondent is aged 15 or less.

The expression is applied to the 'Food Preferences' page and asks whether the respondent's age is not greater than 15.

Only if the answer is 16 or above will the expression = false and the page will be displayed.

The following expression can then be applied to the 'Not Eligible' page so this page appears if the respondent's age is 15 or less.

The result for a survey respondent is as follows:

Binary Operators

Operation
Symbol

Add, Concat

+

Subtract

-

Multiply

*

Divide

/

Divide and floor

//

Modulus

%

Power of

^

Logical AND

&&

Logical OR

||

Worked example

In this example the || symbol is used to display or hide a question based on the answers to two preceeding questions.

The above expression works as follows:

It is true and therefore hidden when ('do you have children that go to school is yes) OR (do you have children that go to university is yes)

The expression is then inverted using ! to display it for the same configuration.

if you want to hide something (result being true), it is important to use ||and not && because true || false = true (hidden), while true && false = false (displayed)`.

in operator

The in operator can be used to check whether an element appears in a list of options

Worked example

In this example the in operator is used to display or hide a question based on a selection from a proceeding checkbox list.

The expression is true and therefore hidden when 'apples' is selected as a response to the question 'what fruit do your like to eat?'

The expression is then inverted using ! to display it for the same configuration.

Ternary operator

The ternary operator, also known as the conditional operator, is very useful when writing complex logical expressions. It works in a similar way to the 'if' function in excel.

It works by first checking to see if the first segment of an expression is true. If so the consequent segment is evaluated. Otherwise, the alternative is. If the consequent section is missing, the test result itself will be used instead.

Worked example of the ternary operator

In this example the ternary operator is used to hide or display the question 'Did you like this survey' based on the respondent's answer to the question 'Do you agree to participate in this survey'

The above expression works as follow:

The first statement is evaluated initially. It asks whether the answer to the question 'do you agree to participate in this survey' is 'Yes'.

If the first statement equates to false the alternative is returned. The alternative appears at the end of the logical expression after the : symbol. In this instance the alternative returns true**.**

If the first statement equates to true the consequent segment is evaluated. The consequent statement appears immediately after the ? symbol. In this instance the consequent returns false.

The consequent segment can include a series of logical expressions as shown in the example below. The alternative statement can be written as either true or false. This makes the ternary operator highly flexible and suitable for writing complex logical expressions

Additional example of the ternary operator

In this example the ternary operator is used to display or hide a page based on the answers to three preceeding questions.

The above expression works as follow:

The first statement is evaluated initially. It asks whether the option 'a person without disabilities' has been selected as an option from the question 'Which do you consider yourself to be?

If it equates to false the alternative is returned. The alternative appears after the : at the end of the statement and in this instance is true**.**

If it equates to true the consequent segment is evaluated.

In this instance the consequent segment asks whether the answer to the question 'do you currently work for the government of the country you live in' is NOT equal to No or whether the answer to the question 'do you currently work for a United Nations Country Team is NOT equal to No. This expression will only be false if the answer to both these questions is 'No'.

The result of this logical expression is return a true expression result (and hide the page) in all circustances except if the respondent is a person without disabilities who does not currently work for the government of the country they live in or currently work for a United Nations Country Team.

Parentheses

Parentheses operate as you would expect them to. They are used in logical expressions primarily to modify the normal order of operations. In an expression involving parentheses, the terms inside the parentheses () are evaluated first.

They can be combined with the ! expression to invert the expression within the brackets as shown in a number of examples given above.

Custom Transforms

The application adds custom transforms to simplify expressions. Transforms use the | pipe operator.

Using 'Length' to customise the number of checkbox options selected

You can use the 'length' operator to customise the number of checkbox optionsd you require a respondent to select.

For instance limiting the number of answers of a question `What colors do you like` to no more than 2 answers, add this expression to the validity logic expression:

A custom validation message can then be added under the settings option. This message will appear if a respondents checks 3 or more colours. The message will be announced to screen readers.

If a respondents selects more than 3 colours they will be able to continue to fill in the survey. However they will not be able to submit the survey until the required number of options have been selected. Respondents will be redirected to the 'invalid' question so the issue can be resolved.

This short video shows how the validity logic can be applied to customising the number of boxes of a checkbox question you require a respondent to select.

Using 'Length' to customise the number of order question items to be ordered

In a similar way, the 'length' operator can be used to customise the number of order question items to be ordered by a respondent.

For instance to require respondents to order all the items in this list the following validity expression can be used:

The expression result will be 'true' (and therefore 'valid') when:

  • The number of options ordered is more than 2 (ie all the options are selected)

  • OR (||) no options are selected. The number of options selected is blank ("")

A custom validation message can be added under the settings option. This message will appear if a respondents orders some but not all of the options. The message will be announced to screen readers.

If a respondents orders some but not all of the options, they will be able to continue to fill in the survey. However they will not be able to submit the survey until either all or none of the options have been ordered. Respondents will be redirected to the 'invalid' question so the issue can be resolved.

This logical expression has a limitation. If the question is marked as 'required' the question will appear in red when the page loads even before the question has received focus. The only way to resolve this currently is to accept this behaviour or not to mark the question as required

This short video shows how the validity logic can be applied to customising the number of order question items to be ordered.

short video showing how a comparitive logical expression can be used to hide or display pages depending upon a respondent's age
Screenshot showing how the !(>) can be used to show or hide a page depending upon an respondent's age
Screenshot showing how the !(>) can be used to show or hide a page depending upon an respondent's age
Screenshot showing how the || expression can be used to display or hide a question based on the answers to two proceeding questions
Screenshot showing how the in operator can be used to display or hide a question based on a selection from a prceeding checkbox list
Screenshot showing how ! can be used to invert a logical expression
Screenshot showing a worked example of the ternary operator
Example of the ternary operator being used to display or hide a page based on the answers to three preceeding questions
Screenshot showing how the 'Length' operator can be used to limit the number of options a respondent can select for a checkbox group question
Screenshot showing how a custom validation message can be added under the 'settings' option.
Screenshot showing a logical expression to customise the number or items to be ordered
Screenshot showing how a custom validation message can be added under the 'settings' option.
Screenshot showing an example of a logical expression being used to hide or display a page based on a respondents age.
Screenshot showing an example of a logical expression being used to hide or display a page based on a respondents age.
Screenshot showing how the || symbol can be used to display or hide a question based on the answers to two preceeding questions.
Screenshot showing an example of a logical expression using the 'in' operator
Screenshot showing a simple worked example of using the ternary operator to hide or display a question based on a respondent's answer to a previous question
Screenshot showing how the length operator can be used to limit the number of checkboxes which are checked
Screenshot showing how a custom validation message can be created under the settings option.