forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
knockout.validation.d.ts
233 lines (204 loc) · 7.39 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
// 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 {
/**
* indicates whether to walk the ViewModel (or object)
* recursively, or only walk first-level properties.
*/
deep?: boolean;
/**
* indicates whether the returned errors object
* is a ko.computed or a simple function
*/
observable?: boolean;
/**
* indicates whether changes to observableArrays inside
* the model should cause the validator to re-run
*/
live?: boolean;
}
interface KnockoutValidationValidateOptions {
throttle?: number;
}
interface KnockoutValidationConfiguration {
/**
* Allows HTML in validation messages
*/
allowHtmlMessages?: boolean;
/**
* Indicates whether css error classes are added only
* when properties are modified or at all times
* @type {[type]}
*/
decorateElementOnModified?: boolean;
/**
* Indicates whether to assign an error class to the <input> tag
* when your property is invalid
*/
decorateInputElement?: boolean;
/**
* If defined, the CSS class assigned to both <input> and validation message elements
*/
errorClass?: string;
/**
* The CSS class assigned to validation error <input> elements, must have decorateInputElement set to true
*/
errorElementClass?: string;
/**
* The CSS class assigned to validation error messages
*/
errorMessageClass?: string;
/**
* Shows tooltips using input 'title' attribute. False hides them
*/
errorsAsTitle?: boolean;
/**
* Shows the error when hovering the input field (decorateElement must be true)
*/
errorsAsTitleOnModified?: boolean;
grouping?: KnockoutValidationGroupingOptions;
/**
* If true validation will insert either a <span> element or the template
* specified by messageTemplate after any element (e.g. <input>)
* that uses a KO value binding with a validated field
*/
insertMessages?: boolean;
/**
* Indicates whether validation messages are triggered only
* when properties are modified or at all times
*/
messagesOnModified?: boolean;
/**
* The id of the <script type="text/html"></script>
* that you want to use for all your validation messages
*/
messageTemplate?: string;
/**
* Indicates whether to assign validation rules to your ViewModel
* using HTML5 validation attributes
*/
parseInputAttributes?: boolean;
/**
* Register custom validation rules defined via ko.validation.rules
*/
registerExtenders?: boolean;
validate?: KnockoutValidationValidateOptions;
/**
* Add HTML5 input validation attributes to form elements
* that ko observable's are bound to
*/
writeInputAttributes?: boolean;
}
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