dimah-formv0.6.1
Reference

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.

TypeAnswerConstraints
textstringminLength, maxLength, pattern (regex)
numbernumbermin, max, integer
booleanbooleanunsetOnOff — off writes null instead of false
selectstringoptions. Answer must be an option value
multiSelectstring[]options. No duplicate values
emailstringEmail address
datestringYYYY-MM-DD. Optional min / max in the same format
fileFileAnswer{ 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.

Next steps

On this page