|
| 1 | +import DocPage from '@docs/doc-page'; |
| 2 | +import CodeExample from '@docs/code-example'; |
| 3 | + |
| 4 | +<DocPage> |
| 5 | + |
| 6 | +# Frequently Asked Questions (FAQ) |
| 7 | + |
| 8 | +## Q. Docs for version 1.x still available anywhere? |
| 9 | + |
| 10 | +**A.** Docs are available [here](https://pokus-next.firebaseapp.com/) or you can use [old branch](https://github.com/data-driven-forms/react-forms/tree/v1/packages/react-renderer-demo/src/app/pages) on GitHub. |
| 11 | +<br /> |
| 12 | + |
| 13 | +--- |
| 14 | +<br /> |
| 15 | + |
| 16 | +## Q. Is there a way for a field to access another field's value and receive updates whenever it changes? |
| 17 | + |
| 18 | +**A.** Right now, there are two standard ways how to update the second component: |
| 19 | + |
| 20 | +1) Set [subscription](/components/renderer#optionalprops) |
| 21 | + |
| 22 | +```jsx |
| 23 | +<FormRenderer |
| 24 | + schema={schema} |
| 25 | + FormTemplate={FormTemplate} |
| 26 | + componentMapper={componentMapper} |
| 27 | + onSubmit={console.log} |
| 28 | + subscription={{values: true}} |
| 29 | +/> |
| 30 | +``` |
| 31 | + |
| 32 | +All fields will be updated when values are changed. It will hurt the performance, but in small forms it should be ok. |
| 33 | + |
| 34 | +2) use [formSpy](/components/form-spy) |
| 35 | + |
| 36 | +```jsx |
| 37 | +<FormSpy subscription={{values: true}}> |
| 38 | + {(formState) => <CustomComponent />} |
| 39 | +</FormSpy> |
| 40 | +``` |
| 41 | +<br /> |
| 42 | + |
| 43 | +--- |
| 44 | +<br /> |
| 45 | + |
| 46 | +## Q. How to fill the form values programmatically? |
| 47 | + |
| 48 | +**A.** Use [useFormApi.change(name, value)](/hooks/use-form-api#change) function that allows you to set any value you need. |
| 49 | +<br /> |
| 50 | + |
| 51 | +--- |
| 52 | +<br /> |
| 53 | + |
| 54 | +## Q. Is there a way to divide my form into hierarchial (nested) subsections using only the schema? |
| 55 | + |
| 56 | +**A.** |
| 57 | + |
| 58 | +You can divide the form by using default [sub-form components](/mappers/sub-form). |
| 59 | + |
| 60 | +``` |
| 61 | +{ |
| 62 | + "component": "sub-form", |
| 63 | + "title": "Subform", |
| 64 | + "description": "This is a subform", |
| 65 | + "name": "subform", |
| 66 | + "fields": [ |
| 67 | + { |
| 68 | + "name": "carrot", |
| 69 | + "label": "Carrot", |
| 70 | + "component": "text-field" |
| 71 | + } |
| 72 | + ] |
| 73 | +} |
| 74 | +``` |
| 75 | + |
| 76 | +Or you can easily implement your own component: |
| 77 | + |
| 78 | +```jsx |
| 79 | +import { useFormApi } from '@data-driven-forms/react-form-renderer'; |
| 80 | + |
| 81 | +const Section = ({fields}) => { |
| 82 | + const { renderForm } = useFormApi(); |
| 83 | + |
| 84 | + return (<div> |
| 85 | + {renderForm(fields)} |
| 86 | + </div>); |
| 87 | +} |
| 88 | +``` |
| 89 | +<br /> |
| 90 | + |
| 91 | +--- |
| 92 | +<br /> |
| 93 | + |
| 94 | +## Q. I see 'useField must be used inside of a Form' component error when using DDF |
| 95 | + |
| 96 | +**A.** You have probably mixed different DDF modules. Please see [optimization](/optimization) page. |
| 97 | + |
| 98 | +</DocPage> |
0 commit comments