-
Notifications
You must be signed in to change notification settings - Fork 36
/
index.d.ts
110 lines (77 loc) · 4.02 KB
/
index.d.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
interface HyperformOptions {
/** When true, disable the high-level API. Default: false. */
strict?: boolean;
/** Prevent Enter in input fields to submit the form. Default: false. */
preventImplicitSubmit?: boolean;
/** Whether and when fields should be re-validated automatically. */
revalidate?: 'oninput' | 'onblur' | 'hybrid' | 'onsubmit' | 'never';
/** Whether the non-standard valid event should be triggered. Default: true. */
validEvent?: boolean;
/** Whether the <fieldset> element should be treated like a normal input field, e.g. allowing it to receive an error message. Default: true. */
extendFieldset?: boolean;
/** Whether input fields with the non-standard attribute novalidate should be exempted from validation. Default: true. */
novalidateOnElements?: boolean;
/** CSS class names to use instead of the default ones. */
classes?: {
warning?: string,
valid?: string,
invalid?: string,
validated?: string
}
/** Whether to include input elements without name attribute as validation candidates. Default: false. */
validateNameless?: boolean;
}
export interface HyperformRenderer {
/** called when a warning should become visible */
attachWarning: (warning: HTMLElement, element: HTMLElement) => void;
/** called when a warning should vanish */
detachWarning: (warning: HTMLElement, element: HTMLElement) => void;
/** called when feedback to an element's state should be handled ie: showing and hiding warnings */
showWarning: (element: HTMLElement, wholeFormValidated: boolean) => void;
/** set the warning's content */
setMessage: (warning: HTMLElement, message: string, element: HTMLElement) => void;
}
export interface HyperformValidator {
(element: HTMLElement): boolean;
}
export interface HyperformStatic {
version: string;
/** initializes hyperform on a specific form or globally */
(target: Window | HTMLFormElement, options?: HyperformOptions): void;
/** TODO: add documentation */
ValidityState(element: HTMLElement): ValidityState;
/** check, if an element will be subject to HTML5 validation at all */
willValidate(element: HTMLElement): boolean;
/** represents the value of the element, interpreted as a date */
valueAsDate(element: HTMLElement, value: any): Date | null;
/** represents the value of the element, interpreted as a number */
valueAsNumber(element: HTMLElement, value: any): Number;
/** add custom validation logic for specific elements */
addValidator(element: HTMLElement, validate: HyperformValidator): void;
/** override default renderer methods */
setRenderer<T extends keyof HyperformRenderer>(renderer: T, action: HyperformRenderer[T]): void;
/** check an element's validity with respect to it's form */
checkValidity(element: HTMLElement): boolean;
/** check element's validity and report an error back to the user */
reportValidity(element: HTMLElement): boolean;
/** set a custom validity message or delete it with an empty string */
setCustomValidity(element: HTMLElement, message: string): void;
/** TODO: add documentation */
stepDown(element: HTMLElement, amount: number): void;
/** TODO: add documentation */
stepUp(element: HTMLElement, amount: number): void;
/** get the validation message for an element, empty string, if the element satisfies all constraints. */
validationMessage(element: HTMLElement): string;
/** set the language for Hyperform’s messages */
setLanguage(lang: string): HyperformStatic;
/** add a lookup catalog "string: translation" for a language */
addTranslation(lang: string, catalog: any): HyperformStatic;
/** register custom error messages per element */
setMessage(element: HTMLElement, validator: HyperformValidator, message: string): HyperformStatic;
/** TODO: add documentation and types */
addHook(hook: any, action: any, position: any): HyperformStatic;
/** TODO: add documentation and types */
removeHook(hook: any, action: any): HyperformStatic;
}
declare const Hyperform: HyperformStatic;
export default Hyperform;