2
2
React Form Fields: Core
3
3
------------------------------
4
4
5
- See [ API.md] ( https://github.com/react-form-fields/core/blob/master/API.md ) for details
6
5
7
6
## Requirements
8
7
@@ -21,55 +20,7 @@ yarn add @react-form-fields/core
21
20
22
21
### How to Create a Form Field
23
22
24
- ``` tsx
25
- import FieldCoreBase , { IPropsFieldBase , IStateFieldBase } from ' @react-form-fields/core/components/FieldCoreBase' ;
26
-
27
- interface IState extends IStateFieldBase {
28
- // your state props
29
- }
30
-
31
- interface IProps extends IPropsFieldBase {
32
- // your props
33
- }
34
-
35
- class MyComponentField extends FieldCoreBase <IProps , IState > {
36
- // If you need getDerivedStateFromProps dont forget to call super
37
- static getDerivedStateFromProps(props : IProps , currentState : IState ): IState {
38
- const state = super .getDerivedStateFromProps (props , currentState );
39
- // your logic....
40
- return state ;
41
- }
42
-
43
- onChange = event => {
44
- const value = this .mask .clean (event .target ? event .target .value : event );
45
-
46
- this .setState ({ touched: true }); // <-- important to show the error
47
- this .props .onChange (value );
48
- }
49
-
50
- render() {
51
- const { label, name } = this .props ;
52
-
53
- return (
54
- <Fragment >
55
- { /* import: register the field in the validation context */ }
56
- <ValidationContextRegister field = { this } />
57
-
58
- { /* isRequired: check if validation prop contains the required rule */ }
59
- <label >{ label } { this .isRequired ? ' *' : ' ' } </label >
60
- <input
61
- name = { name }
62
- value = { this .getMaskedValue }
63
- onChange = { this .onChange }
64
- />
65
-
66
- { /* errorMessage will be null if submitted and touched are false */ }
67
- { this .errorMessage ? <p class = " error" >{ this .errorMessage } </p > : null }
68
- </Fragment >
69
- );
70
- }
71
- }
72
- ```
23
+ See [ HOW_TO_USE.md] ( https://github.com/react-form-fields/core/blob/master/HOW_TO_USE.md ) for details
73
24
74
25
### Common Masks
75
26
0 commit comments