Formiz
This component creates a form context.
Import
import { Formiz } from "@formiz/core";Props
id
Allows you to pass a custom id, which will be used to create the ids of the fields. By default, it is generated automatically.
<Formiz id="custom-id">{/* Your fields here */}</Formiz>autoForm
- Set to
trueor'form'to wrap children in a<form>element with autosubmit()on form submission. - Set to
'step'to wrap children in a<form>element with autosubmitStep()on form submission.
<Formiz autoForm>
{/* your fields here */}
<button type="submit">Submit</button>
</Formiz>connect
Allows you to connect your form with the useForm() hook.
See useForm() documentation for more details.
import { Formiz, useForm } from "@formiz/core";
const MyForm = () => {
const form = useForm();
return <Formiz connect={form}>{/* Your fields here */}</Formiz>;
};initialValues
Allows you to pass some initial values to the form. If a field is mounted, it will lookup into this object to set his initial value. This is usefull when you are getting data from an API like an edit page.
<Formiz initialValues={{ myField: "my initial value" }}>
{/* your fields here */}
</Formiz>initialStepName
Allows you to define the initial step.
<Formiz initialStepName="step-2">{/* your fields here */}</Formiz>onSubmit(values)
Function triggered on form submission, whether it is valid or not.
<Formiz onSubmit={(values) => console.log(values)}>
{/* your fields here */}
</Formiz>onValidSubmit(values)
Function triggered on form submission, only if it is valid.
<Formiz onValidSubmit={(values) => console.log(values)}>
{/* your fields here */}
</Formiz>onInvalidSubmit(values)
Function triggered on form submission, only if it is invalid.
<Formiz onInvalidSubmit={(values) => console.log(values)}>
{/* your fields here */}
</Formiz>onValuesChange(values)
Function triggered on any form field value change.
<Formiz onValuesChange={(values) => console.log(values)}>
{/* your fields here */}
</Formiz>onValid()
Triggered when the form is valid.
Instead you can get isValid value with the useForm()
hook.
<Formiz onValid={() => console.log("form is valid")}>
{/* your fields here */}
</Formiz>onInvalid()
Triggered when the form is invalid.
Instead you can get isValid value with the useForm()
hook.
<Formiz onInvalid={() => console.log("form is invalid")}>
{/* your fields here */}
</Formiz>