Formsort
Search…
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:
1
[
2
{
3
"label": "The first choice", // Displayed to the user
4
5
"value": "choice_a", // Stored in the answers
6
7
"disabled": false, // [Optional]: Whether the choice
8
// is disabled
9
10
"imageUrl": "https://..." // [Optional]: If loading choices
11
// for a select question with
12
// images, the URL of the image.
13
}
14
]
Copied!

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.
1
function myFunction(): IChoice<string>[] { // readonly line
2
3
const date = new Date();
4
const choices: IChoice<string>[] = [];
5
const numDays = 10;
6
for (let i = 0; i < numDays; i++) {
7
date.setDate(date.getDate() + 1)
8
choices.push({
9
label: date.toDateString(),
10
value: date.toISOString()
11
})
12
}
13
return choices;
14
}
Copied!
See calculated answers for more information on writing calculated answers inline.
Last modified 1yr ago