Skip to main content

FormShell

The React Admin form the edit and create shells wrap: SimpleForm, the save toolbar, and the cross-cutting form machinery around them.

Use it directly for a form that is not an <Edit> or a <Create> — a dialog collecting action parameters, a settings screen. Inside a generated view the form already exists; there, formActions on SchemaEdit is the smaller change.

Example​

import {FormShell, TextInput, NumberInput, SubmitButton} from 'habarico';

<FormShell onSubmit={saveSettings} onPostSubmit={() => notify('Saved')}>
<TextInput source="name" />
<NumberInput source="price" />
</FormShell>

Props​

NameTypeDefaultDescription
childrenReactNode—The inputs
onSubmitSubmitHandler<FieldValues>save from the save contextTakes over submitting entirely
onPostSubmit() => void—Runs after a successful submit
validateSimpleFormProps['validate']—Form-level validation
recordRaRecordrecord from contextUsed as the root record and when merging defaultValues; the form itself is populated from the React Admin record context
formActionsReactNodea SubmitButtonReplaces the toolbar content
defaultValuesRecord<string, unknown>—Values pre-filled into the form
modeSimpleFormProps['mode']'onBlur'When validation runs — 'onSubmit' reports errors only after a submit attempt

defaultValues are merged against the record, so a value the record already carries is not overwritten by the default.

Validation runs on blur: a field reports its error as soon as it loses focus, rather than letting the user fill the whole form and find out at submit time. That applies both to the rules the backend declared and to any validate of your own. Pass mode="onSubmit" where the earlier feedback gets in the way — a wizard step whose fields are filled out of order, for instance.

What it sets up​

Beyond the form and its toolbar, the shell provides the machinery every generated form relies on:

  • UploadingProvider — so a save waits for files still uploading,
  • FormInputSourcesProvider — the registry array boxes use to declare their target,
  • RootRecordContext — the outer record, for boxes rendering a nested one,
  • the draft controller — autosaves the form locally and offers to restore it, when draftEnabled is on,
  • the navigation guard — the confirm dialog before leaving a dirty form, when navigationGuard is on,
  • the form-extension registry — see Form extensions.

Both flags are set on SchemaAdmin and default to off.

The toolbar is a ViewToolbar and follows the same presentation rule as ViewContent's bottom bar: an in-flow footer on a page, DialogActions inside a dialog.

See also​