FormRootError
export default () => { interface Values { email: string; password: string; } const form = useForm<Values>({ defaultValues: { email: "max@mustermann.de", password: "password", }, }); return ( <Section> <Form form={form} onSubmit={() => { form.setError("root", { message: "Login fehlgeschlagen", }); }} > <Field name="email" rules={{ required: "Bitte gib eine E-Mail ein", }} > <TextField> <Label>E-Mail</Label> </TextField> </Field> <Field name="password" rules={{ required: "Bitte gib ein Passwort ein", }} > <TextField type="password"> <Label>Passwort</Label> </TextField> </Field> <FormRootError /> <ActionGroup> <SubmitButton>Speichern</SubmitButton> </ActionGroup> </Form> </Section> ); }
Eigener Inhalt
Ohne Children zeigt die FormRootError die message des Root-Fehlers als Alert
an. Children ersetzen diesen Alert, zum Beispiel für einen Alert mit Heading und
Text. Sie werden nur gerendert, solange ein Root-Fehler gesetzt ist. Als
Funktion erhalten sie den Root-Fehler und können den Inhalt so nach dessen
type wählen.
Properties
| Property | Type | Description |
|---|---|---|
children | ReactNode | Custom content shown instead of the default alert. Rendered only while a root error is set. A function receives the root error, e.g. to pick the content by its `type`. |