Field types
Built-in types, constraints, showWhen, and answer inference.
Eight built-in types. Each one has a definition schema, a validator, and an $Infer answer.
| Type | Answer | Constraints |
|---|---|---|
text | string | minLength, maxLength, pattern (regex) |
number | number | min, max, integer |
boolean | boolean | unsetOnOff — off writes null instead of false |
select | string | options. Answer must be an option value |
multiSelect | string[] | options. No duplicate values |
email | string | Email address |
date | string | YYYY-MM-DD. Optional min / max in the same format |
file | FileAnswer | { id?, url?, name?, contentType?, size? }. At least one of id, url, or name. No bytes |
boolean without unsetOnOff stores false for off, so a required yes/no can submit No.
file has no built-in widget. Your app writes the metadata after upload.
import type { FileAnswer, SelectOption } from "@dimah-form/react";SelectOption
Prop
Type
FileAnswer
Prop
Type
FormField
Shared keys on every field. Type-specific keys (min, options, pattern, unsetOnOff) stay on the same object.
Prop
Type
showWhen
import type { FieldShowWhenCompare } from "@dimah-form/react";Prop
Type
A hidden field is omitted from visibleFields. Submit strips its answer. Group
rules with all (every rule) or any (one rule). Examples:
Forms.
$Infer
required: true makes an unconditional key required. Optional fields and
fields with showWhen are optional because they may be absent.
type ExampleAnswers = Form["$Infer"]["answers"]["example"];
// {
// name: string;
// role: "admin" | "user";
// age?: number;
// tags?: ("frontend" | "backend")[];
// }Another type uses defineFieldType. Its $Infer token is the answer type.