dimah-formv0.6.1
React

Custom rendering

Bind FormFieldBinding to inputs in your own design system.

q.field(id) is the contract for a control. Pass it to your input, shadcn, or design system.

@dimah-form/ui wraps the same binding. This page is the headless path.

import type { FormFieldBinding } from "@dimah-form/react";

Prop

Type

components/select-field.tsx
"use client";

import { emptyToNull, fieldLabel, fieldOptions } from "@dimah-form/react";
import type { FormFieldBinding } from "@dimah-form/react";

export function SelectField(binding: FormFieldBinding) {
  const { field, value, error, disabled, onChange } = binding;
  if (!field) return null;

  return (
    <label>
      {fieldLabel(field)}
      <select
        value={typeof value === "string" ? value : ""}
        disabled={disabled}
        onChange={(event) => onChange(emptyToNull(event.target.value))}
      >
        <option value="">Select…</option>
        {fieldOptions(field).map((option) => (
          <option key={option.value} value={option.value}>
            {option.label}
          </option>
        ))}
      </select>
      {error ? <span>{error}</span> : null}
    </label>
  );
}

Branch the rest on field.type inside one dispatcher: checkbox for boolean, checkboxes for multiSelect, type="number" / type="date" / type="email" for the others. file is metadata your app writes after upload — there is no file input in the protocol.

onChange(null) deletes the answer. emptyToNull("") does that for text controls. An empty multiSelect should be null, not [], when you want the key removed. For boolean, write null when field.unsetOnOff === true; otherwise write false so a required yes/no field can submit “No.”

Helpers

Exported from @dimah-form/react and @dimah-form/server:

Helper
fieldLabel(field)field.label ?? field.id
fieldOptions(field){ value, label?, meta? }, label falls back to value
emptyToNull(value)"" → null
formatAnswer(field, value, fieldTypes?)English display string. Custom types use defineFieldType.format when fieldTypes includes them

Steps

Filter q.visibleFields by field.meta.step yourself. @dimah-form/ui groups the same key with FormSteps. visibleSteps is exported from that package.

Next steps

On this page