FormProvider
Overview
FormProvider
is a component that allows you to define the wizard fields that you want to use in your react application. It provides a way to specify the field components that will be used to render the wizard fields, and allows you to use either the default field components provided by the @tutim/fields
library, or your own custom field components.
Installation
To use FormProvider
, you will need to install the @tutim/headless
library in your react project. You can do this using npm or yarn:
You will also need to install the @tutim/fields
library if you want to use the default field components provided by the library. You can do this using npm or yarn:
Basic example
To use FormProvider
, you will need to wrap your react application with the FormProvider
component and specify the field components that you want to use. You can do this by passing a fieldComponents
prop to the FormProvider
component, which should be an object with keys that match the type
of the fields you want to use, and values that are the field components themselves.
For example, you can use FormProvider
to specify the default field components provided by the @tutim/fields
library, or you can create your own custom field components and use them in the wizard.
Here is an example of how to use FormProvider
to specify the default field components provided by the @tutim/fields
library:
This will render a form with a single field, using the default field component provided by the @tutim/fields
library. When the form is submitted, the data entered into the field will be logged to the console.
Remote schema example
Forms built on the Admin Portal
could be served in real-time using the FormProvider
add clientId
to your FormProvider Options
use formId
in your forms instead of config in TutimWizard
, useForm
or if you want to manipulate the config, you could also use it with useFormConfig
.
You can customize the form fields by creating your own custom field components and using them
Advanced example
You can customize the form fields by creating your own custom field components and using them with FormProvider
. To do this, you will need to define the custom field components and add them to the fieldComponents
object passed to the FormProvider
component.
For example, you can create a custom field component that renders a button that increments a number when clicked, and use it in the form by specifying the type
of the field as 'custom-field'
:
This will render a form with two fields: a text input field and a custom field that renders a button. The custom field will increment its value by 2 every time the button is clicked. When the form is submitted, the data entered into the fields will be logged to the console.
Last updated