API reference
Entry points
| Import | Holds |
|---|---|
@schema-engine/forms-radiant | createRadiantFormEngine, FormRenderer, schemaFormRegistrations, the recipes, FormController and FormEngineController, and the hosts |
@schema-engine/forms-radiant/index.css | The renderer's stylesheet |
@schema-engine/forms-radiant/registrations | Each element registration by name, such as InputElementRegistration |
@schema-engine/forms-radiant/hooks | Helpers for building elements: combineHandlers and mergeFieldGridHost |
@schema-engine/forms-radiant/primitives | The rendering primitives: FormField, FormFieldElement, FormElement and ChildGrid (its subgrid prop lays a container's children on the tracks of the grid around it) |
@schema-engine/forms-radiant/contexts | formInstanceContext, which the hosts publish to the blocks and recipes of a renderer; an app reads the form with FormController |
createRadiantFormEngine
import { createRadiantFormEngine, schemaFormRegistrations } from '@schema-engine/forms-radiant';
export const engine = createRadiantFormEngine({ elements: schemaFormRegistrations });It takes the options of createFormEngine and returns the same engine type. It prepends the canonical Radiant recipes (radiantRecipes) to the recipes you pass, so a recipe of yours with the same $type replaces a built-in one. It registers no element: pass schemaFormRegistrations, a subset or your own. Engine and registrations covers the options.
FormRenderer
A view that renders a form with Radiant elements. It validates the config with the engine, so a plain config object or a normalized one both work.
| Prop | Meaning |
|---|---|
engine | The form engine. A form that only renders on the client passes it here. See Server rendering for the rest |
config | A form config, or the result of engine.defineForm or engine.validateForm |
defaultValues | Values the form starts from, typed from the config |
onSubmit | Called with the values that passed validation, and { setServerErrors, fetch }. Typed from the config |
onChange | Called with the form's values when they change, never for a touch or an error |
onAction | Called with each submit action that succeeded. Typed by the engine's actions |
onActionResults | Called with the results of every trigger that ran actions, as in React. The same results reach the se-action-results event |
navigate | Takes the page to the redirectUrl a submit action set, once the whole submission succeeded. location.assign by default; it replaces a native post |
formatIssue | Words an issue for this renderer's forms. It wins over the engine's |
action, method | A native post target. A form with them and no onSubmit posts natively after validation passes |
class, style | Styling for the host element |
Events
A form announces what its actions and its submission did as bubbling, composed events on its rui-form, so a page with no FormRenderer callback, such as a form rendered on the server, can listen to them.
| Event | detail |
|---|---|
se-action-results | { trigger, results } of every trigger that ran actions |
se-action-submit-start | none: validation passed and the submit actions are about to run |
se-action-submit-invalid | { failures }: empty when the fields have errors |
se-action-submit-complete | { succeeded, results, failures } of the submit actions |
FormRendererElement is the se-form-renderer custom element behind it. Assign engine to it, as a property, to bind a server-rendered form. FormInstance and FormElement are the views for one form and one field.
Registrations
schemaFormRegistrations lists the 18 element registrations of the package, in registration order. Each is also exported by name from @schema-engine/forms-radiant/registrations: InputElementRegistration, TextareaElementRegistration, NumberElementRegistration, SelectElementRegistration, CheckboxElementRegistration, CheckboxGroupElementRegistration, SwitchElementRegistration, RadioElementRegistration, SliderElementRegistration, ComboboxElementRegistration, DropZoneElementRegistration, FieldSetRegistration, InputOTPElementRegistration, PhoneInputElementRegistration, MaskedInputElementRegistration, ArrayElementRegistration, SubmitButtonElementRegistration and SubmissionAlertElementRegistration. Overview maps them to their $type.
The schemas, metadata and value declarations of these elements are the default element contracts of @schema-engine/forms/default-elements, which radiantElements binds with bindRegistry; each registration shares the contract's schema by identity, and the package adds only the Radiant component and, for the phone input, its own validation.
createRadiantPhoneValidationRegistration builds the phone validation rule for a set of countries.
Recipes
radiantRecipes lists the canonical view recipes that createRadiantFormEngine binds: CardRecipe, SplitScreenRecipe, HeroBackgroundRecipe, BareControlsRecipe, WizardRecipe, SidebarWizardRecipe, CardWizardRecipe, HeroWizardRecipe and SplitScreenWizardRecipe. defineRecipe binds your own shell and slots to a recipe spec, and DEFAULT_WIZARD_RECIPE names the recipe a multi-step form without a view falls back to. See Layouts.
Controllers
FormController and FormEngineController give a custom element access to the form it sits in. Overview describes them, and Form controls shows a custom control that uses the native events.
Debugging
FormDebugger and FormDebuggerElement render a panel with the form's meta and state, for development.