Providing choices via API or calculation

Dynamically loading select choices

Standard select questions have a discrete set of choices to select from that are defined at the time that the form is created. If the list of choices to present to your responders isn't known at the time the form is being built, or changes often, it's possible to load choices dynamically, from an API lookup or calculation.

Trying to look up an answer from an API? See API answers.

See this video comparing different approaches to specifying choices for a visual walkthrough.

Choice schema

Dynamically-loaded choices, whether from an API or calculated locally, must adhere to the following format:

[
  {
    "label": "The first choice", // Displayed to the user
    
    "value": "choice_a",         // Stored in the answers
    
    "disabled": false,           // [Optional]: Whether the choice
                                 // is disabled
                                 
    "imageUrl": "https://..."    // [Optional]: If loading choices
                                 // for a select question with
                                 // images, the URL of the image.
  }
] 

Configuring an API lookup or calculation

With a select question selected, go to the CHOICES tab, and select Load choices dynamically.

External API

With External API selected, you will be able to configure an API lookup from which values will be retrieved.

If the API you are connecting to does not return results of the form described in the schema above, you can use a result mapping function to transform the result.

See API answers for more on how to specify API lookups.

Calculated locally

When calculated locally is enabled, you will be able to use Typescript to output the answers for responder.

For example, the following definition would create ten days of future dates as choices.

function myFunction(): IChoice<string>[] { // readonly line

  const date = new Date();
  const choices: IChoice<string>[] = [];
  const numDays = 10;
  for (let i = 0; i < numDays; i++) {
      date.setDate(date.getDate() + 1)
      choices.push({
          label: date.toDateString(),
          value: date.toISOString()
      })
  }
  return choices;
}

See calculated answers for more information on writing calculated answers inline.

Last updated