1. Install FormEngine
Create a new Vite app (or use your existing React project):2. Define the form schema
Createsrc/contactForm.json. This JSON object fully describes the form — fields, validation rules, conditional logic, and layout:
src/contactForm.json
errorType: "MuiErrorWrapper"tells FormEngine to use Material UI’s error display component- Each field has a unique
key— this key is used in the form data object schema.validationsis an array of Zod-backed validation rulesrenderWhenis a JavaScript expression evaluated against the live form data — the “company” field only renders whencontactTypeis"business"- The submit button’s
onClickevent runsvalidatefirst (stops if invalid), then calls our customonSubmitaction
3. Render the form
Replacesrc/App.tsx with:
src/App.tsx
http://localhost:5173. You should see the form with the three visible fields. Select
“Business” from the dropdown — the “Company name” field appears. Try submitting without filling in
required fields — validation errors appear inline.
4. How validation works
FormEngine validation rules live in the JSON schema, not in your React code. The available built-in rules are backed by Zod:| Rule key | What it validates | Example args |
|---|---|---|
required | Field must have a value | { message: "Required" } |
email | Must be a valid email | { message: "Invalid email" } |
min | Minimum string length or number value | { limit: 2 } |
max | Maximum string length or number value | { limit: 100 } |
url | Must be a valid URL | — |
pattern | Must match a regex | { regex: "^[A-Z]" } |
5. How conditional fields work
TherenderWhen property accepts a JavaScript expression string that’s evaluated against the live form state:
form.data is the current form data object — a plain JS object where each key matches a field’s
key value. The expression is re-evaluated on every form change. When the expression returns
false, the field is hidden and its value is excluded from form data.
You can write any JavaScript expression:
6. Handle form submission with an API call
Replace thealert in the onSubmit action with a real API call:
event.data object contains the current form values, keyed by field key:
7. Load the schema from an API
One of FormEngine’s main advantages is that the form schema doesn’t have to be a static file. You can fetch it from an API, a database, or any other source:Full example on GitHub
The complete working code for this tutorial is available in the FormEngine repository examples.Next steps
- Multi-step form tutorial — build a wizard form with multiple steps and per-step validation
- Conditional logic reference — full
renderWhendocumentation - Validation reference — all built-in rules and custom validators
- Using FormEngine with Next.js — integrate this into a Next.js app
- FormEngine Designer — let users build these forms visually without writing JSON