Skip to content

Form Steps Guide

@enlolab/forms allows you to create multi-step forms with conditional navigation. This guide explains how to configure steps and their conditions.

steps: {
step1: {
id: "step1",
fields: ["field1", "field2", "field3"]
},
step2: {
id: "step2",
fields: ["field4", "field5"]
}
}

Unique identifier for the step. Must match the key in the steps object.

Array of field names that should be displayed in this step.

Optional property that defines the default next step if no conditions are met:

step1: {
id: "step1",
fields: ["field1", "field2"],
defaultNext: "step2"
}

Array of conditions that determine the next step based on form values:

step1: {
id: "step1",
fields: ["field1", "field2"],
next: [
{
conditions: [
{
field: "field1",
operator: "equals",
value: "yes"
}
],
operator: "AND",
target: "step2"
}
]
}

@enlolab/forms supports the following condition operators:

OperatorDescriptionExample
equalsField equals value{ operator: "equals", value: "yes" }
notEqualsField not equals value{ operator: "notEquals", value: "no" }
containsField contains value{ operator: "contains", value: "test" }
notContainsField does not contain value{ operator: "notContains", value: "test" }
greaterThanField is greater than value{ operator: "greaterThan", value: 10 }
lessThanField is less than value{ operator: "lessThan", value: 5 }
greaterThanOrEqualField is greater than or equal to value{ operator: "greaterThanOrEqual", value: 10 }
lessThanOrEqualField is less than or equal to value{ operator: "lessThanOrEqual", value: 5 }
isTrueField is true{ operator: "isTrue" }
isFalseField is false{ operator: "isFalse" }
isEmptyField is empty{ operator: "isEmpty" }
isNotEmptyField is not empty{ operator: "isNotEmpty" }

You can combine multiple conditions using AND/OR operators:

step1: {
id: "step1",
fields: ["age", "hasLicense", "country"],
next: [
{
conditions: [
{
field: "age",
operator: "greaterThanOrEqual",
value: 18
},
{
field: "hasLicense",
operator: "isTrue"
}
],
operator: "AND",
target: "step2"
},
{
conditions: [
{
field: "country",
operator: "equals",
value: "US"
}
],
operator: "OR",
target: "step3"
}
],
defaultNext: "step4"
}
const myForm = FormFactory({
formId: "example-form",
fields: {
age: {
type: "number",
label: "Age",
},
hasLicense: {
type: "checkbox",
label: "Do you have a driver's license?",
},
country: {
type: "select",
label: "Country",
options: [
{ label: "United States", value: "US" },
{ label: "Canada", value: "CA" },
{ label: "Mexico", value: "MX" },
],
},
},
steps: {
personalInfo: {
id: "personalInfo",
fields: ["age", "hasLicense", "country"],
next: [
{
conditions: [
{
field: "age",
operator: "greaterThanOrEqual",
value: 18,
},
{
field: "hasLicense",
operator: "isTrue",
},
],
operator: "AND",
target: "drivingInfo",
},
],
defaultNext: "generalInfo",
},
drivingInfo: {
id: "drivingInfo",
fields: ["licenseNumber", "expiryDate"],
},
generalInfo: {
id: "generalInfo",
fields: ["name", "email"],
},
},
});
  1. Clear Step Names: Use descriptive IDs for your steps
  2. Logical Grouping: Group related fields in the same step
  3. Conditional Logic: Use conditions to create dynamic form flows
  4. Default Path: Always provide a defaultNext to ensure the form can proceed
  5. Validation: Consider step validation requirements when designing the flow