|
4 | 4 |
|
5 | 5 | Component Base to create a form field. |
6 | 6 |
|
7 | | -| Props | Required | Type | Description | |
8 | | -|-------------------|----------|------------------------|------------------------------------------------------------------------| |
9 | | -| name | false | string | | |
10 | | -| value | false | any | | |
11 | | -| submitted | false | boolean | flag to set if form was submited (also can be set by setFormSubmitted) | |
12 | | -| validation | false | string | rules of validation | |
13 | | -| validationContext | false | object { prop: value } | extra fields for validation bind (ex. required_if) | |
14 | | -| errorMessage | false | string | custom error message from external validation | |
| 7 | +| Props | Required | Type | Description | |
| 8 | +|--------------------------|----------|------------------------|------------------------------------------------------------------------| |
| 9 | +| name | false | string | | |
| 10 | +| value | false | any | | |
| 11 | +| submitted | false | boolean | flag to set if form was submited (also can be set by setFormSubmitted) | |
| 12 | +| validation | false | string | rules of validation | |
| 13 | +| validationContext | false | object { prop: value } | extra fields for validation bind (ex. required_if) | |
| 14 | +| validationAttributeNames | false | object { prop: value } | see: https://github.com/skaterdav85/validatorjs#custom-attribute-names | |
| 15 | +| errorMessage | false | string | custom error message from external validation | |
15 | 16 |
|
16 | 17 | ### How to Create a Form Field |
17 | 18 |
|
18 | 19 | ```tsx |
19 | 20 | import FieldCoreBase, { IPropsFieldBase, IStateFieldBase } from '@react-form-fields/core/components/FieldCoreBase'; |
20 | 21 |
|
21 | | -interface IState extends IStateFieldBase { |
| 22 | +interface IState extends IStateFieldBase { //<-- extends |
22 | 23 | //your state props |
23 | 24 | } |
24 | 25 |
|
25 | | -interface IProps extends IPropsFieldBase { |
| 26 | +interface IProps extends IPropsFieldBase { //<-- extends |
26 | 27 | // your props |
27 | 28 | onChange: (value: string) => void; |
28 | 29 | } |
29 | 30 |
|
30 | 31 | class MyComponentField extends FieldCoreBase<IProps, IState> { |
31 | | - //If you need getDerivedStateFromProps dont forget to call super |
| 32 | + //[optional] If you need getDerivedStateFromProps dont forget to call super |
32 | 33 | static getDerivedStateFromProps(props: IProps, currentState: IState): IState { |
33 | 34 | const state = super.getDerivedStateFromProps(props, currentState); |
34 | 35 | // your logic.... |
|
0 commit comments