Web · Components
SchemaForm
Generates a form from a schema or JSON definition: fields, labels, required flags, validation, sections and steps in one component.
Live example
Preview
Code
Events
- Events appear here when you interact with the preview.
Translation from a dictionary (switch language)
Without a schema, from a JSON definition
Import
Generates a form from a schema or JSON definition: fields, labels, required flags, validation, sections and steps in one component. With a Zod schema, field types are derived from the schema; definitions can also come from the server as JSON.
- Fields are the ready-made field components (
TextField,SelectField,PhoneField…); validation, error display and mobile behavior are the same. - Types:
text,email,password,url,textarea,number,select,multiselect,autocomplete,radio,checkbox,switch,date,datetime,daterange,time,file,slider,rating,tags,otp,color,richtext,phone,country,array,hidden. New types are added withcomponents. array: repeating rows (FieldArray); row fields viafields, with add/remove/drag to reorder built in.- Conditional field with
when:{ field: "type", equals: "business" }. - Titled sections with
sections, a step-by-step wizard withsteps. - Multiple columns with
columns; one column on narrow screens. draft,defaultValues,state,action,onValidSubmitare the same as inForm.
For derivation from the schema see deriveFields. Label via .meta({ title }), description via .describe(), field settings via .meta({ ui: { type: "textarea" } }), option names via .meta({ labels: { istanbul: "İstanbul" } }).
Translation: the label, description, placeholder, hint, option names, section/step titles and button texts are translated if they are a key in the dictionary (UIProvider messages) and update when the language changes (.meta({ title: "login.email" })); otherwise they are shown as is. An option without a name is generated from its value ("istanbul" → "İstanbul"). To translate a list from the dictionary use .meta({ ui: { optionsKey: "cities" } }) (cities.istanbul), and to translate the whole form from one root use i18nPrefix.
Examples
translateText
functionReturns the translation if the text is a dictionary key, otherwise the text itself ("login.title" → "Sign in"; "Full name" → "Full name").
humanizeValue
functionGenerates a readable label from an option value: "istanbul" → "Istanbul", "corporateAccount" → "Corporate account". Values starting with an uppercase letter ("TR") or containing digits or dots stay as they are.
localizeOptions
functionDisplay labels of options. Order: a label that is a dictionary key → prefix.field.options.value → optionsKey.value → label → label generated from the value.
localizeField
functionTranslates the texts of a field definition (label, description, tooltip, placeholder, options) from the dictionary. Text without a dictionary entry stays as is, so the schema can contain both plain text and keys.
Examples
localizeSection
functionTranslates the title and description of a section or step.
humanizeName
functionGenerates a label from a name: "birthDate" → "Birth date", "address.city" → "City".
deriveFromJsonSchema
functionDerives field definitions from a JSON Schema. Objects are flattened with parent.child names; property order is preserved.
deriveFields
functionDerives field definitions from a schema (one that offers Standard JSON Schema, such as Zod 4.2+). The label comes from title (.meta({ title })), the description from description (.describe()), field settings from .meta({ ui: { … } }).
Derivation rules:
- string →
text;email/url/date/timeformats map to their own type;maxLength> 200 →textarea. - enum →
radiowith 3 or fewer options, otherwiseselect. - number →
number(min/max); no decimals for integers. - boolean →
checkbox;z.literal(true)is a required checkbox. - enum array →
multiselect, string array →tags, object array →array(row fields infields; add, remove, drag to reorder). - object → its fields named
parent.child.
Examples
isFieldVisible
functionDoes the field's condition match?
FormFieldType
typeBuilt-in field types.
FormTranslator
interfaceTranslator: the result of useT or i18n.getT() (t and t.has).
| Name | Type | Description |
|---|---|---|
has | (key: string): boolean | Whether the key exists in the dictionary. |
LocalizeOptions
interfaceTranslation options.
| Name | Type | Description |
|---|---|---|
prefix? | string | Dictionary root for field texts. With "forms.signup", these keys are looked up for the city field: - forms.signup.city (label when it is a string) or forms.signup.city.label - forms.signup.city.description, .placeholder, .tooltip - forms.signup.city.options.istanbul (option label) |
FormFieldOption
typeOption: a string or { value, label }.
FormFieldCondition
interfaceCondition for showing the field (can be written as JSON). When several keys are given, all of them must match.
| Name | Type | Description |
|---|---|---|
field | string | Name of the field to look at. |
equals? | unknown | Visible when the value equals this. |
notEquals? | unknown | Visible when the value does not equal this. |
in? | readonly unknown[] | Visible when the value is one of these. |
filled? | boolean | true: visible when the field is filled, false: when it is empty. |
FormFieldConfig
interfaceDefinition of a single form field. Definitions without functions can be stored as JSON and sent from the server.
| Name | Type | Default | Description |
|---|---|---|---|
name | string | Field name; may be nested ("address.city"). | |
type? | FormFieldType | (string & {}) | "text" | Field type. Not needed when it can be derived from the schema. |
label? | string | Label. Defaults to the schema's title or text generated from the name. If it is a dictionary key ("login.email") its translation is shown and updated when the language changes; otherwise it is shown as is. | |
description? | string | Help text. Defaults to the schema's description. | |
tooltip? | string | ⓘ tooltip next to the label. | |
placeholder? | string | Placeholder. | |
required? | boolean | Required (asterisk on the label, browser validation). | |
disabled? | boolean | Disabled. | |
options? | readonly FormFieldOption[] | Options (select, multiselect, radio, autocomplete, tags). An option without a label gets one generated from its value ("newYork" → "New york"); a label that is a dictionary key is translated. | |
optionsKey? | string | Dictionary root for option labels: with "cities", the label of the istanbul option comes from the cities.istanbul key. Useful for translating the same list in many forms. | |
min? | number | string | Minimum value (number, slider, date). | |
max? | number | string | Maximum value. | |
step? | number | Step. | |
minLength? | number | Minimum characters. | |
maxLength? | number | Maximum characters. | |
defaultValue? | unknown | Initial value (can also be given with Form defaultValues). | |
span? | number | "full" | 1 | How many grid columns it spans (when columns > 1). "full" spans the row. On narrow screens every field is full width. |
when? | FormFieldCondition | readonly FormFieldCondition[] | ((values: Record<string, unknown>) => boolean) | Visible (and submitted) only when the condition matches. | |
props? | Record<string, unknown> | Extra props passed as is to the field component (e.g. { rows: 5 }). | |
hidden? | boolean | Hide (to not show a field coming from the schema). | |
fields? | readonly FormFieldConfig[] | Fields of a row for the array type; names are relative to the row ("name", "address.city"). Rows are added, removed and reordered by dragging with FieldArray (disable with props: { sortable: false }). min/max limit the row count. Derived automatically from an array of objects in the schema (z.array(z.object(...))). | |
columns? | number | Column count of the row fields for the array type (single column on narrow screens). |
FormSection
interfaceField group: a titled section or a wizard step.
| Name | Type | Description |
|---|---|---|
title? | string | Section title (step name in a wizard). |
description? | string | Description. |
fields | readonly (string | FormFieldConfig)[] | Fields of the section: a name (from the schema) or a definition. |
columns? | number | Column count in this section. |
optional? | boolean | Optional step in a wizard (Skip button). |
FormFieldMeta
typeField settings that can be written into the schema with .meta({ ui: … }).
Custom field renderer: takes the definition and returns the field.
SchemaFormProps
interfaceProps of the SchemaForm component.
Extends: Omit<FormProps<Schema>, "children">
| Name | Type | Default | Description |
|---|---|---|---|
fields? | readonly (string | FormFieldConfig)[] | Fields and their order. If a name is given, the definition is derived from the schema; if a definition is given, it overrides what is derived from the schema ({ name: "role", type: "radio" }). If omitted, all fields in the schema are shown in order. | |
sections? | readonly FormSection[] | Splits the fields into titled sections (instead of fields). | |
steps? | readonly FormSection[] | Splits the fields into wizard steps: each step becomes a Wizard step, validated with the schema when moving forward. With draft, the current step is stored too. | |
columns? | 1 | 2 | 3 | 4 | 1 | Number of columns on wide screens; always one column on narrow screens. |
i18nPrefix? | string | Dictionary root of the field texts. With "forms.signup", the label of the city field comes from forms.signup.city (or forms.signup.city.label), its description from forms.signup.city.description, and its options from forms.signup.city.options.<value>. For a missing key the text in the schema is used. | |
submitLabel? | ReactNode | "Gönder" | Text of the submit button (can be a dictionary key). |
resetLabel? | ReactNode | true | Reset button: true with the default text, or with the given text. | |
hideSubmit? | boolean | Hide the submit button (if you put your own button with children). | |
components? | Partial<Record<string, FormFieldRenderer>> | Custom field renderers by type. To replace a built-in type or add a new one ({ iban: (f) => <TextField {...f} mask="iban" /> }). | |
children? | ReactNode | Shown after the fields, before the buttons. | |
wizard? | Omit<WizardProps<Schema>, "steps" | "schema" | "onComplete" | "defaultValues" | "draft" | "action" | "state"> | Extra props passed to Wizard when the wizard is used. |