forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
knockout.validation.d.ts
160 lines (132 loc) · 5.14 KB
/
knockout.validation.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// Type definitions for Knockout Validation
// Project: https://github.com/ericmbarnard/Knockout-Validation
// Definitions by: Dan Ludwig <https://github.com/danludwig>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../knockout/knockout.d.ts" />
interface KnockoutValidationGroupingOptions {
deep?: boolean;
observable?: boolean;
}
interface KnockoutValidationConfiguration {
registerExtenders?: boolean;
messagesOnModified?: boolean;
messageTemplate?: string;
insertMessages?: boolean;
parseInputAttributes?: boolean;
writeInputAttributes?: boolean;
decorateInputElement?: boolean;
errorClass?: string;
errorElementClass?: string;
errorMessageClass?: string;
grouping?: KnockoutValidationGroupingOptions;
}
interface KnockoutValidationUtils {
isArray(o: any): boolean;
isObject(o: any): boolean;
values(o: any): any[];
getValue(o: any): any;
hasAttribute(node: Element, attr: string): boolean;
isValidatable(o: any): boolean;
insertAfter(node: Element, newNode: Element): void;
newId(): number;
getConfigOptions(element: Element): KnockoutValidationConfiguration;
setDomData(node: Element, data: KnockoutValidationConfiguration): void;
getDomData(node: Element): KnockoutValidationConfiguration;
contextFor(node: Element): KnockoutValidationConfiguration;
isEmptyVal(val: any): boolean;
}
interface KnockoutValidationAsyncCallbackArgs {
isValid: boolean;
message: string;
}
interface KnockoutValidationAsyncCallback {
(result: boolean): void;
(result: KnockoutValidationAsyncCallbackArgs): void;
}
interface KnockoutValidationRuleBase
{
message: string;
}
interface KnockoutValidationRuleDefinition extends KnockoutValidationRuleBase {
validator(value: any, params: any): boolean;
}
interface KnockoutValidationAsyncRuleDefinition extends KnockoutValidationRuleBase {
async: boolean;
validator(value: any, params: any, callback: KnockoutValidationAsyncCallback): void;
}
interface KnockoutValidationAnonymousRuleDefinition {
validation: KnockoutValidationRuleDefinition;
}
interface KnockoutValidationRuleDefinitions {
date: KnockoutValidationRuleDefinition;
dateISO: KnockoutValidationRuleDefinition;
digit: KnockoutValidationRuleDefinition;
email: KnockoutValidationRuleDefinition;
equal: KnockoutValidationRuleDefinition;
max: KnockoutValidationRuleDefinition;
maxLength: KnockoutValidationRuleDefinition;
min: KnockoutValidationRuleDefinition;
minLength: KnockoutValidationRuleDefinition;
notEqual: KnockoutValidationRuleDefinition;
number: KnockoutValidationRuleDefinition;
pattern: KnockoutValidationRuleDefinition;
phoneUS: KnockoutValidationRuleDefinition;
required: KnockoutValidationRuleDefinition;
step: KnockoutValidationRuleDefinition;
unique: KnockoutValidationRuleDefinition;
}
interface KnockoutValidationRule {
rule: string;
params: any;
message?: string;
condition?: () => boolean;
}
interface KnockoutValidationErrors {
(): string[];
showAllMessages(): void;
showAllMessages(show: boolean): void;
}
interface KnockoutValidationGroup {
errors?: KnockoutValidationErrors;
isValid?: () => boolean;
isAnyMessageShown?: () => boolean;
}
interface KnockoutValidationLocalizationDictionary {
[key: string]: string;
}
interface KnockoutValidationStatic {
init(options?: KnockoutValidationConfiguration, force?: boolean): void;
reset(): void;
group(obj: any, options?: any): KnockoutValidationErrors;
formatMessage(message: string, params: string): string;
addRule<T>(observable: KnockoutObservable<T>, rule: KnockoutValidationRule): KnockoutObservable<T>;
addAnonymousRule(observable: KnockoutObservable<any>, ruleObj: KnockoutValidationAnonymousRuleDefinition): void;
insertValidationMessage(element: Element): Element;
parseInputValidationAttributes(element: Element, valueAccessor: () => KnockoutObservable<any>): void;
rules: KnockoutValidationRuleDefinitions;
addExtender(ruleName: string): void;
registerExtenders(): void;
utils: KnockoutValidationUtils;
localize(msgTranslations: KnockoutValidationLocalizationDictionary): void;
defineLocale(newLocale: string, msgTranslations: KnockoutValidationLocalizationDictionary): KnockoutValidationLocalizationDictionary;
locale(newLocale: string): string;
validateObservable(observable: KnockoutObservable<any>): boolean;
}
interface KnockoutStatic {
validation: KnockoutValidationStatic;
validatedObservable<T>(initialValue?: T): KnockoutObservable<T>;
applyBindingsWithValidation(viewModel: any, rootNode?: any, options?: KnockoutValidationConfiguration): void;
}
interface KnockoutSubscribableFunctions<T> {
isValid: KnockoutComputed<boolean>;
isValidating: KnockoutObservable<boolean>;
rules: KnockoutObservableArray<KnockoutValidationRule>;
isModified: KnockoutObservable<boolean>;
error: KnockoutComputed<string>;
setError(error: string): void;
clearError(): void;
}
declare module "knockout.validation" {
export = validation;
}
declare var validation: KnockoutValidationStatic