Can I customize the step answer validation?

Sometimes you need to validate step answer value in a custom way, it can be your API endpoint, custom calculation etc.

For the some of the step types (ones like email, number etc), Quriobot allows the custom validation JavaScript function to be provided (note that the Developer Mode has to be enabled).

To have a custom validation for the step, follow those steps:

Step 1. In the step settings, enable custom answer validation:

Step 2: Implement an async JS function which will validate the answer. Function has such parameters:

  1. answer, String - user input for the given step
  2. getVariableValue, Function(name, callback) - function to get an existing variable value, for example - getVariableValue(‘variableName’, function(value){console.log(value )})
  3. callback, Function(errorMessage) - callback function to call with the validation result. If validation is successful, do NOT pass the errorMessage parameter.

Example for the validation:

function(answer, getVariableValue, callback) {
    if (answer === 'invalid@example.com') {
      // answer is invalid
        callback('Error message')
    } else {
        // answer is valid
      callback()
    }
}

Edit this page