Skip to content

Initial Values

MLForm has two ways to set an initial field value.

SourceBest forExample
defaultValue on a fieldSchema-owned defaults that travel with the schema.Default confidence threshold.
initialValues in mountFormHost-app state, user profile data, restored drafts.Saved customer id or dashboard filter.

initialValues takes precedence over defaultValue.

mountForm(container, {
transport: createJsonTransport({ endpoint: "/api/predict" }),
schema: {
fields: [
{ id: "threshold", kind: "number", label: "Threshold", defaultValue: 0.7 },
{ id: "prompt", kind: "text", label: "Prompt" },
],
},
initialValues: {
threshold: 0.85,
prompt: "Existing draft text",
},
});

Put business defaults in the schema. Put host-specific or user-specific state in initialValues.

Avoid mixing both for the same field unless the precedence is intentional. Tests should assert the final value through mounted.form.getValues() when defaults matter.