Skip to content

Commit 627f0c2

Browse files
committed
add get fileds
Signed-off-by: danieloprado <[email protected]>
1 parent 7be39d6 commit 627f0c2

File tree

3 files changed

+4
-8
lines changed

3 files changed

+4
-8
lines changed

components/FieldCoreBase.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { ErrorMessages } from 'validatorjs';
33

44
import { getMask, IMaskFunction } from '../mask';
55
import { validate } from '../validator';
6-
import { FieldValidation, IFieldValidationContext } from '../validator/context';
76
import CustomMessage from './CustomMessage';
87

98
export interface IStateFieldBase {
@@ -27,9 +26,6 @@ export default abstract class FieldCoreBase<
2726
P extends IPropsFieldBase = IPropsFieldBase,
2827
S extends IStateFieldBase = IStateFieldBase
2928
> extends React.PureComponent<P, S> {
30-
static contextType = FieldValidation;
31-
context: IFieldValidationContext;
32-
3329
constructor(props: any) {
3430
super(props);
3531
this.state = { showError: false, errorMessage: null } as S;
@@ -84,10 +80,6 @@ export default abstract class FieldCoreBase<
8480
};
8581
}
8682

87-
public componentWillUnmount() {
88-
this.context && this.context.unregister(this);
89-
}
90-
9183
public setFormSubmitted = (submitted: boolean) => {
9284
this.setState({ submitted });
9385
}

components/ValidationContext.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import FieldCoreBase from './FieldCoreBase';
66
export default class ValidationContext extends React.PureComponent<{}> {
77
public fields: FieldCoreBase<any, any>[] = [];
88
private registerFields: IFieldValidationContext = {
9+
getFields: () => {
10+
return this.fields;
11+
},
912
register: field => {
1013
this.fields.push(field);
1114
},

validator/context.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as React from 'react';
33
import FieldCoreBase from '../components/FieldCoreBase';
44

55
export interface IFieldValidationContext {
6+
getFields: () => FieldCoreBase[];
67
register: (field: FieldCoreBase) => void;
78
unregister: (field: FieldCoreBase) => void;
89
}

0 commit comments

Comments
 (0)