Resource Detail Form

Generic CRUD form with field types and validation

SaaSForms

Overview

ResourceDetailForm renders a complete form from a schema definition, supporting view, edit, and create modes. It handles field rendering, validation, sections, loading/error states, and unsaved changes warnings out of the box.

Usage

import { ResourceDetailForm } from "@leanicon/web-builder-library/saas";

const schema = {
  id: "user",
  name: "user",
  title: "User Profile",
  fields: [
    { name: "name", type: "text", label: "Name", validation: { required: true } },
    { name: "email", type: "email", label: "Email", validation: { required: true } },
  ],
};

<ResourceDetailForm
  schema={schema}
  values={{ name: "John", email: "[email protected]" }}
  mode="view"
  onSave={async (values) => console.log(values)}
  onCancel={() => {}}
/>;

Variants

View Mode

User Profile

View and manage user information

John
Doe

Edit Mode

User Profile

Create Mode

New User

Loading

User Profile

—
—

With Error

Error

Failed to load user data. Please try again.

Single Column

User Profile

No Header

John

Dark

User Profile

John
Doe

Props

NameTypeDefaultRequiredDescription
schemaResourceSchema—YesSchema defining the form structure
valuesRecord<string, unknown>—NoInitial/current values for the form
modeenumviewNoInitial form mode
loadingbooleanfalseNoWhether form is in loading state
errorstring—NoError message to display
localestringen-USNoLocale for formatting (e.g., 'en-US', 'es-ES')
showHeaderbooleantrueNoWhether to show the form header with title
classNamestring—NoCustom class name for the form container
formRefRefObject<FormActions<T> | null>—NoRef for accessing form actions
onSave(values: T) => void | Promise<void>—YesCalled when save is clicked with valid data
onCancel() => void—YesCalled when cancel is clicked
onModeChange((mode: FormMode) => void)—NoCalled when mode changes
onValidationChange((isValid: boolean, errors: Record<string, string>) => void)—NoCalled when validation state changes
onChange((values: T, fieldName: string) => void)—NoCalled when any field value changes
onEdit(() => void)—NoCalled when edit button is clicked (view mode)
onDelete(() => void)—NoCalled when delete is requested (if enabled)
onRetry(() => void)—NoCalled when retry is clicked after error