-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormContext.ts
36 lines (27 loc) · 1.18 KB
/
FormContext.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import * as PropTypes from "prop-types";
import { ModelValue, ModelInterface, ModelError } from "../Model";
export interface FormContext {
values: ModelValue[];
addError: (newError: ModelError) => void,
getError: (attribute: string) => ModelError | undefined,
onChange: (attribute: string, value: any) => any;
onMount: (attribute: string, element: HTMLElement) => void;
onUnmount: (attribute: string) => void;
onReset: () => void;
readonly validate: (group: string) => Promise<ModelError[]>;
readonly getDOMElement:
(attribute: string) => HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement | void;
isLoading: boolean;
}
export const FormContextTypes: {[P in keyof FormContext]: PropTypes.Validator<any>} = {
values: PropTypes.arrayOf(PropTypes.object).isRequired,
addError: PropTypes.func.isRequired,
getError: PropTypes.func.isRequired,
onChange: PropTypes.func.isRequired,
onMount: PropTypes.func.isRequired,
onUnmount: PropTypes.func.isRequired,
onReset: PropTypes.func.isRequired,
validate: PropTypes.func.isRequired,
getDOMElement: PropTypes.func.isRequired,
isLoading: PropTypes.bool.isRequired,
};