Advanced

Interpolation

Formulate allows creating questions and answers dynamically as the user runs through the form. This makes it very flexible, but comes with a downside. We can't make a list of all possible questions in advance, we have to wait for the user to make it to the end and submit the form.

This means a single question that has a dynamic element in the question text could be interpreted as multiple different questions in the submissions view.

Let's use this very simple form as an example:

let name = await form.short("What's your name?");
await form.short(`Hi ${name}! What's your email address?`, {email: true});

Now because the second question interpolates name into the question text, this looks like a different question every time it's submitted. Case in point:

Each variation of the second question was counted as a separate question, which is not at all what we wanted!

There are two easy ways to fix this, fortunately.

Wrap with interpolate()

Wrap the dynamic parts of your questions with form.interpolate(), which masks them with underscores at submission time. Here's a version of the example above that uses interpolate():

let name = await form.short("What's your name?");
await form.short(`Hi ${form.interpolate(name)}! What's your email address?`, {email: true});

Which fixes things up nicely in the submissions view:

interpolate() is also aliased to interp() and i(), so these are all equivalent:

form.i(name);
form.interp(name);
form.interpolate(name);

Provide an explicit name

You can pass a name to any question type as an option, which will override that question's text at submission time. Here's a version of the example above that uses name:

let name = await form.short("What's your name?");
await form.short(`Hi ${name}! What's your email address?`, {
  email: true, 
  name: 'email-address'
});

This has a similar effect, using the common name to group responses together:

Linting

We plan to provide more advanced linting rules in the online editor so errors like the one in the original example above are caught automatically. Until that's done, though, this is something you'll need to remember while building forms on Formulate.