You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This hook returns object containing following information:
22
22
23
-
```jsx
24
-
{
25
-
blur: (name) =>void, // calls onBlur event on field with given name
26
-
change: (name, value) =>void, // calls onChange event on field with given name
27
-
focus: (name) =>void, // calls onFocus event on field with given name
28
-
getFieldState: (name) => object, // returns a state of given field, state contains input and meta information of field
29
-
getRegisteredFields: () => string[], // returns an array of field names that are rendered in DOM
30
-
getState: () => object, // returns an object with whole form state. More info https://final-form.org/docs/final-form/types/FormState
31
-
pristine: bool, // true if the all field values is === to the initial values, false if the values are !==.
32
-
renderForm: (defaultSchema) =>void, // function that is used by form renderer to render form fields defined by defaultSchema; can be used for schema nesting
33
-
valid: bool //true if all fields have no validation or submission errors. false otherwise.
34
-
}
35
-
```
23
+
## renderForm
24
+
25
+
*(fields: schema) => React.Element*
26
+
27
+
If you want to render fields from a component (`tabs`, `subform`, etc.) you can use `renderForm(fields)` function.
28
+
29
+
## getState
30
+
31
+
*() => FormState*
32
+
33
+
Using `getState` components you get an access to [the form state](https://final-form.org/docs/final-form/types/FormState). Be aware of subscription - if your component is not subscribed to the form state, it won't be updated when the state is changed. See [FormSpy](/components/form-spy).
34
+
35
+
## change
36
+
37
+
*(name: string, value: any) => void*
38
+
39
+
You can change value of any field using this function.
40
+
41
+
## focus
42
+
43
+
*(name: string) => void*
44
+
45
+
Calls onFocus event on field with given name.
46
+
47
+
## blur
48
+
49
+
*(name: string) => void*
50
+
51
+
Calls onBlur event on field with given name.
52
+
53
+
## getFieldState
54
+
55
+
*(name: string) => FormFieldState*
56
+
57
+
Returns a state of given field. State contains input and meta information of the field.
58
+
59
+
## getRegisteredFields
60
+
61
+
*() => string[]*
62
+
63
+
Returns an array of field names that are currently rendered in DOM. Useful to know when you collect variables in wizard forms.
64
+
65
+
## pristine
66
+
67
+
*boolean*
68
+
69
+
True if the all field values is === to the initial values, false if the values are !==. Same as in the FormState.
70
+
71
+
## valid
72
+
73
+
*boolean*
74
+
75
+
True if all fields have no validation or submission errors. false otherwise. Same as in the FormState.
Data Driven Forms team provides and mantains basic set of components for following design systems:
19
+
Data Driven Forms team provides and mantains basic set of components for following design systems. You can use them to build forms without ingerating your own components.
Copy file name to clipboardExpand all lines: packages/react-renderer-demo/src/pages/introduction.md
+30-7Lines changed: 30 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,21 +5,30 @@ import CodeExample from '@docs/code-example';
5
5
6
6
# Data Driven Forms Introduction
7
7
8
-
Data Driven Forms converts JSON form definitions into fully functional React forms.
9
-
It uses [React Final Form](https://github.com/final-form/react-final-form) for the form state management.
10
-
It is highly recommended to check their documentations first to fully understand how
11
-
the [Data Driven Forms](https://github.com/data-driven-forms/react-forms) libraries work.
8
+
Data Driven Forms converts JSON form definitions (schemas) into fully functional React forms with the provided set of features.
12
9
13
-
All you need is to [install](/installation) the form renderer and choose the component mapper you want ([or create your own](/mappers/custom-mapper)).
10
+
## Form state management
14
11
15
-
Import `FormRenderer` from the react-form-renderer. This component takes four required props: FormTemplate, schema, componentMapper and onSubmit. You can read about them [here](/components/renderer#requiredprops).
12
+
Data Driven Forms uses [React Final Form](https://github.com/final-form/react-final-form) for the form state management. It is recommended to check their documentations first to fully understand how the [Data Driven Forms](https://github.com/data-driven-forms/react-forms) libraries work. However, it's not required to use DDF library.
16
13
17
-
You can check the simple example below.
14
+
## Schema
15
+
16
+
[A schema](/schema/introduction) is a JSON object controlling the whole form. Using schema you define form fields and its attributes.
17
+
18
+
## How to start
19
+
20
+
All you need is to [install](/installation) the form renderer and then to choose components you want to use. You can use one of provided mappers to start building forms right away ([or integrate your own components](/mappers/custom-mapper)). The integration is simple - all it takes is just a single [useFieldApi](/hooks/use-field-api) hook.
21
+
22
+
Then you can import `FormRenderer` from the `@data-driven-forms/react-form-renderer`. This component takes four required props: **FormTemplate**, **schema**, **componentMapper** and **onSubmit**. You can read about them [here](/components/renderer#requiredprops).
23
+
24
+
Following example shows basic usage of Data Driven Forms library with our [Material UI mapper](/mappers/mui-component-mapper).
Following articles can give you more insights about Data Driven Forms and why/how to use it in you projects.
31
+
23
32
### Introduction of data driven approach
24
33
25
34
[This article](https://medium.com/javascript-in-plain-english/data-driven-approach-to-forms-with-react-c69fd4ea7923) presents basics of the data driven approach and why to choose it.
@@ -28,4 +37,18 @@ You can check the simple example below.
28
37
29
38
[This article](https://medium.com/javascript-in-plain-english/data-driven-form-building-in-react-30768b49e625) presents basics of the data driven form building. It is a great point to start if you are new with this library.
30
39
40
+
## Comparison with other form libraries
41
+
42
+
### Form state management
43
+
44
+
You can find many of already existing and well-established libraries such as Formik, React Hook Form, or React Final Form. These libraries are focused on providing form state management solutions. Data Driven Forms is using one of them - React Final Form - to enhance the developer experience and to provide consistent way for building complex forms. Form state management is completely abstracted in Data Driven Forms, so developers can focus on the only thing that really matters - building the most accessible web forms.
45
+
46
+
### Data driven libraries
47
+
48
+
Also, there are multiple libraries generating forms from schemas (i.e. Uniforms, AntD Form component). Mostly these libraries are using one of well-known formats such as JSON Schemas or GraphQL schemas. Data Driven Forms implements its own format to provide the most simple representation of forms - it's not being used to define data, it's directly designed to define forms so it's simple, logical and it allows to use many of form-specific features.
49
+
50
+
Data Driven Forms provides complex conditional logic to hide your fields, fully dynamic wizard forms, and much more. Also, its API allows to store complex forms in databases, so you can reuse forms in multiple developer environments.
51
+
52
+
If users need to use generate forms from GraphQL, all that is needed is to convert the GraphQL schema to DDF one.
Using [useFormApi](/hooks/use-form-api) you can get access to mutliple form methods without connecting a form field. Some most used methods are following:
66
+
67
+
**renderForm**
68
+
69
+
*(fields) => React.Element*
70
+
71
+
If you want to render fields from a component (`tabs`, `subform`, etc.) you can use `renderForm(fields)` function.
72
+
73
+
**getState**
74
+
75
+
*() => FormState*
76
+
77
+
Using `getState` components you get an access to the form state. Be aware of subscription - if your component is not subscribed to the form state, it won't be updated when the state is changed. See [FormSpy](/components/form-spy).
78
+
79
+
**change**
80
+
81
+
*(name, value) => void*
82
+
83
+
You can change value of any field using this function.
84
+
85
+
---
86
+
63
87
## Register component in component mapper
64
88
65
89
To be able to use your component in the schema, you need to register the component in your component mapper.
Copy file name to clipboardExpand all lines: packages/react-renderer-demo/src/pages/schema/clear-on-unmount.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,8 @@ import CodeExample from '@docs/code-example';
5
5
6
6
# Clear on unmount
7
7
8
+
*boolean*
9
+
8
10
When using dynamic forms where more fields share the same name, the value is preserved when a user switches the field. You can disable this behavior by setting
9
11
`clearOnUnmount` option in the renderer component or in the schema of the field. The option in the schema has always higher priority. (When
10
12
`clearOnUnmount` is set in the renderer and the field has it this attribute set to `false`, the field value will not be cleared.)
Copy file name to clipboardExpand all lines: packages/react-renderer-demo/src/pages/schema/cleared-value.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,8 @@ import DocPage from '@docs/doc-page';
5
5
6
6
# Cleared value
7
7
8
+
*any*
9
+
8
10
The value to send upon a submit if the field is empty. This wildcard value can be used to distinguish between an untouched field and a cleared one (it will be only used when field has initialValue). For example if you have a form that edits an entity and you would like to clear an attribute. Some APIs require the value to be set to null to register the change.
0 commit comments