Cross-question validations enable you to check responses across multiple survey question blocks to ensure they meet specific criteria. This feature supports high-quality data collection by preventing respondents from entering inconsistent or invalid data across related questions.

Unlike standard validations that apply to a single question, cross-question validations evaluate the relationship between two or more blocks. When a respondent’s answers fail the defined logic, an informative error message is displayed on all referenced blocks to prompt a correction.

Validations are configured at the survey level using Vault expression syntax and referenced by individual blocks. This ensures a consistent configuration experience similar to setting up visibility conditions.

Configuration

To implement a cross-question validation, you must update two areas of the Survey JSON: the validations array at the highest level in the survey JSON and the validationSettings array in specific blocks.

Survey-Level Validations

Define the logic for your validations in the Validations array. Each validation is an object containing a unique name and a logic function.

Parameter Type Description
name String Required. A unique identifier for the validation within the survey.
function String Required. The Vault Expression logic that must evaluate to a boolean.

Syntax and Operators

  • Block Reference: Use the short notation block.{blockName}.answer to refer to specific question responses.
  • Logical Operators: Supports ==, !=, <, >, <=, >=, &&, and ||.
  • Math Operators: Supports +, -.
  • Functions: Supports FindValue() for checking whether a value exists within a set of responses (for example, in a set of multiple choice questions).

Block-Level Settings

Any block whose answer is evaluated in a validation must reference that validation in its Validation Settings array. This ensures that the error message is displayed for the question when the validation fails.

Parameter Type Description
validation String Required. Must match the name defined in the survey.validations array.
message String Required. The error message that is displayed to the respondent if the function evaluates to false.

Supported Block Types

Cross-question validations can reference the following block types:

  • Single Choice
  • Multiple Choice
  • NRS (Numeric Rating Scale)
  • VAS (Visual Analogue Scale)
  • Number Entry (Must be configured for a single answer)

Restrictions:

  • Validations cannot reference Text, Date, Time, Datetime, Joint Count, Pain Detect, Free Draw, or Number Entry blocks configured for more than one answer.
  • Validations cannot reference blocks located in Repeat Sections, Table Sections, or different Survey Parts.
  • Validations cannot reference blocks that have Conditions configured.
  • Validations cannot reference blocks that have an Optional Answer configured.

Validation Behavior

Error Display

The validation will only run if all blocks referenced in the function have been completed or responded to. Once all referenced blocks have been addressed, if the validation logic evaluates to false, the defined error message is displayed on each block and the respondent is unable to continue or submit the survey until the respondent updates their responses to pass the validation.

JSON Examples

Math Logic

This example ensures the sum of “less sleep” and “no sleep” does not exceed 7.



```
{
"label": "Sleep Survey",
"description": "A survey about sleep quality.",
...
    "validations": [
      {
        "name": "nights_less_than_7",
        "function": "block.less_sleep.answer + block.no_sleep.answer <= 7"
      }
    ],
    "blocks": [
      {
        "type": "numberEntry",
        "name": "less_sleep",
        "heading": "How many nights in the last week did you get less sleep than usual?",
        "validationSettings": [
          {
            "validation": "nights_less_than_7",
            "message": "Nights of less sleep and nights of no sleep cannot be more than 7."
          }
        ]
      },
      {
        "type": "numberEntry",
        "name": "no_sleep",
        "heading": "How many nights in the last week did you get no sleep at all?",
        "validationSettings": [
          {
            "validation": "days_less_than_7",
            "message": "Nights of less sleep and nights of no sleep cannot be more than 7."
          }
        ]
      }
    ]
}