Skip to main content

Prefilling forms

It is possible to prefill the fields in a form with predefined values. That way, you can import data into the form.

📝 Importing data

To import data, you need to use the onImport event of the runner. This event fires when the runner instance is created. Use one of the Import functions to import the actual data. To match the data you want to import with the right fields (blocks) in the form, you use the internal identifier of each value in the form (these so called keys are automatically generated by the builder) or use the data identifiers (alias) set by the form creator.

import { run } from "@tripetto/runner-autoscroll";
import { Import } from "@tripetto/runner";

run({
definition: /* Supply your form definition here */,
onImport: (instance) => {
// This example assumes the form has two text fields with
// the data identifiers (aliases) `FIRSTNAME` and `LASTNAME`.
Import.fields(instance, [
{
name: "FIRSTNAME",
value: "John",
},
{
name: "LASTNAME",
value: "Doe",
}
]);

// Or use the generated key of each field
Import.fields(instance, [
{
key: "9ef64ab160ef6096ceecb4561f3eecc37007b669337929393a9d3789fa744f3e",
value: "John",
},
{
key: "e14599867b9fd518459e7ecaf974d33f84f2c3b322f644e838f948c2136eec3a",
value: "Doe",
}
]);
}
});
tip

Data exported from a form instance with one of the Export functions (as shown in the collecting reponse data guide) can be imported directly with the equivalent Import function.

📖 Reference

Have a look at the complete autoscroll runner API reference for detailed documentation. In the examples above, the following symbols were used: