forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
angular-formly.d.ts
574 lines (464 loc) · 19.4 KB
/
angular-formly.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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
// Type definitions for angular-formly 6.18.0
// Project: https://github.com/formly-js/angular-formly
// Definitions by: Scott Hatcher <https://github.com/scatcher>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../angularjs/angular.d.ts" />
declare module 'AngularFormly' {
export = AngularFormly;
}
declare module AngularFormly {
interface IFieldGroup {
data?: Object;
className?: string;
elementAttributes?: { [key: string]: string };
fieldGroup: IFieldConfigurationObject[];
form?: Object;
hide?: boolean;
hideExpression?: string | IExpresssionFunction;
key?: string | number;
model?: string | Object;
options?: IFormOptionsAPI
}
interface IFormOptionsAPI {
data?: Object;
fieldTransform?: Function;
formState?: Object;
removeChromeAutoComplete?: boolean;
resetModel?: Function;
templateManipulators?: ITemplateManipulators;
updateInitialValue?: Function;
wrapper?: string | string[];
}
/**
* see http://docs.angular-formly.com/docs/formly-expressions#expressionproperties-validators--messages
*/
interface IExpresssionFunction {
($viewValue: any, $modelValue: any, scope: ITemplateScope): any;
}
interface IModelOptions {
updateOn?: string;
debounce?: number;
allowInvalid?: boolean;
getterSetter?: string;
timezone?: string;
}
interface ITemplateManipulator {
(template: string | HTMLElement, options: Object, scope: ITemplateScope): string | HTMLElement;
}
interface ITemplateManipulators {
preWrapper?: ITemplateManipulator[];
postWrapper?: ITemplateManipulator[];
}
/**
* see http://docs.angular-formly.com/docs/ngmodelattrstemplatemanipulator
*/
interface ITemplateOptions {
// both attribute or regular attribute
disabled?: boolean;
maxlength?: number;
minlength?: number;
pattern?: string;
required?: boolean;
//attribute only
max?: number;
min?: number;
placeholder?: number | string;
tabindex?: number;
type?: string;
//expression types
onBlur?: string;
onChange?: string;
onClick?: string;
onFocus?: string;
onKeydown?: string;
onKeypress?: string;
onKeyup?: string;
//Bootstrap types
label?: string;
description?: string;
[key: string]: any;
}
/**
* see http://docs.angular-formly.com/docs/field-configuration-object#validators-object
*/
interface IValidator {
expression: string | IExpresssionFunction;
message?: string | IExpresssionFunction;
}
/**
* An object which has at least two properties called expression and listener. The watch.expression
* is added to the formly-form directive's scope (to allow it to run even when hide is true). You
* can specify a type ($watchCollection or $watchGroup) via the watcher.type property (defaults to
* $watch) and whether you want it to be a deep watch via the watcher.deep property (defaults to false).
*
* see http://docs.angular-formly.com/docs/field-configuration-object#watcher-objectarray-of-watches
*/
interface IWatcher {
deep?: boolean; //Defaults to false
expression?: string | { (field: string, scope: ITemplateScope): boolean };
listener: (field: string, newValue: any, oldValue: any, scope: ITemplateScope, stopWatching: Function) => void;
type?: string; //Defaults to $watch but can be set to $watchCollection or $watchGroup
}
// see http://docs.angular-formly.com/docs/field-configuration-object
interface IFieldConfigurationObject {
/**
* Added in 6.18.0
*
* Demo
* see http://angular-formly.com/#/example/other/unique-value-async-validation
*/
asyncValidators?: {
[key: string]: string | IExpresssionFunction | IValidator;
}
/**
* This is a great way to add custom behavior to a specific field. It is injectable with the $scope of the
* field, and anything else you have in your injector.
*
* see http://docs.angular-formly.com/docs/field-configuration-object#controller-controller-name-as-string--controller-f
*/
controller?: string | Function;
/**
* This is reserved for the developer. You have our guarantee to be able to use this and not worry about
* future versions of formly overriding your usage and preventing you from upgrading :-)
*
* see http://docs.angular-formly.com/docs/field-configuration-object#data-object
*/
data?: Object;
/**
* Use defaultValue to initialize it the model. If this is provided and the value of the
* model at compile-time is undefined, then the value of the model will be assigned to defaultValue.
*
* see http://docs.angular-formly.com/docs/field-configuration-object#defaultvalue-any
*/
defaultValue?: any;
/**
* You can specify your own class that will be applied to the formly-field directive (or ng-form of
* a fieldGroup).
*
* see http://docs.angular-formly.com/docs/field-configuration-object#classname-string
*/
className?: string;
elementAttributes?: string;
/**
* An object where the key is a property to be set on the main field config and the value is an
* expression used to assign that property. The value is a formly expressions. The returned value is
* wrapped in $q.when so you can return a promise from your function :-)
*
* see http://docs.angular-formly.com/docs/field-configuration-object#expressionproperties-object
*/
expressionProperties?: {
[key: string]: string | IExpresssionFunction | IValidator;
}
/**
* Uses ng-if. Whether to hide the field. Defaults to false. If you wish this to be conditional, use
* hideExpression. See below.
*
* see http://docs.angular-formly.com/docs/field-configuration-object#hide-boolean
*/
hide?: boolean
/**
* This is similar to expressionProperties with a slight difference. You should (hopefully) never
* notice the difference with the most common use case. This is available due to limitations with
* expressionProperties and ng-if not working together very nicely.
*
* see http://docs.angular-formly.com/docs/field-configuration-object#hideexpression-string--function
*/
hideExpression?: string | IExpresssionFunction;
/**
* This allows you to specify the id of your field (which will be used for its name as well unless
* a name is provided). Note, you can also override the id generation code using the formlyConfig
* extra called getFieldId.
*
* AVOID THIS
* If you don't have to do this, don't. Specifying IDs makes it harder to re-use things and it's
* just extra work. Part of the beauty that angular-formly provides is the fact that you don't need
* to concern yourself with making sure that this is unique.
*
* see http://docs.angular-formly.com/docs/field-configuration-object#id-string
*/
id?: string;
initialValue?: any;
/**
* Can be set instead of type or template to use a custom html template form field. Works
* just like a directive templateUrl and uses the $templateCache
*
* see http://docs.angular-formly.com/docs/field-configuration-object#key-string
*/
key?: string | number;
/**
* This allows you to specify a link function. It is invoked after your template has finished compiling.
* You are passed the normal arguments for a normal link function.
*
* see http://docs.angular-formly.com/docs/field-configuration-object#link-link-function
*/
link?: ng.IDirectiveLinkFn;
/**
* By default, the model passed to the formly-field directive is the same as the model passed to the
* formly-form. However, if the field has a model specified, then it is used for that field (and that
* field only). In addition, a deep watch is added to the formly-field directive's scope to run the
* expressionProperties when the specified model changes.
*
* Note, the formly-form directive will allow you to specify a string which is an (almost) formly
* expression which allows you to define the model as relative to the scope of the form.
*
* see http://docs.angular-formly.com/docs/field-configuration-object#model-object--string
*/
model?: Object | string;
/**
* Allows you to take advantage of ng-model-options directive. Formly's built-in templateManipulator (see
* below) will add this attribute to your ng-model element automatically if this property exists. Note,
* if you use the getter/setter option, formly's templateManipulator will change the value of ng-model
* to options.value which is a getterSetter that formly adds to field options.
*
* see http://docs.angular-formly.com/docs/field-configuration-object#modeloptions
*/
modelOptions?: IModelOptions;
/**
* If you wish to, you can specify a specific name for your ng-model. This is useful if you're posting
* the form to a server using techniques of yester-year.
*
* AVOID THIS
* If you don't have to do this, don't. It's just extra work. Part of the beauty that angular-formly
* provides is the fact that you don't need to concern yourself with stuff like this.
*
* see http://docs.angular-formly.com/docs/field-configuration-object#name-string
*/
name?: string;
/**
* This is used by ngModelAttrsTemplateManipulator to automatically add attributes to the ng-model element
* of field templates. You will likely not use this often. This object is a little complex, but extremely
* powerful. It's best to explain this api via an example. For more information, see the guide on ngModelAttrs.
*
* see http://docs.angular-formly.com/docs/field-configuration-object#ngmodelattrs-object
*/
ngModelAttrs?: {
attribute?: any;
bound?: any;
expression?: any;
value?: any;
};
/**
* Used to tell angular-formly to not attempt to add the formControl property to your object. This is useful
* for things like validation, but not necessary if your "field" doesn't use ng-model (if it's just a horizontal
* line for example). Defaults to undefined.
*
* see http://docs.angular-formly.com/docs/field-configuration-object#noformcontrol-boolean
*/
noFormControl?: boolean;
/**
* Allows you to specify extra types to get options from. Duplicate options are overridden in later priority
* (index 1 will override index 0 properties). Also, these are applied after the type's defaultOptions and
* hence will override any duplicates of those properties as well.
*
* see http://docs.angular-formly.com/docs/field-configuration-object#optionstypes-string--array-of-strings
*/
optionsTypes?: string | string[];
/**
* Can be set instead of type or templateUrl to use a custom html
* template form field. Recommended to be used with one-liners mostly
* (like a directive), or if you're using webpack with the ability to require templates :-)
*
* If a function is passed, it is invoked with the field configuration object and can return
* either a string for the template or a promise that resolves to a string.
*
* see http://docs.angular-formly.com/docs/field-configuration-object#template-string--function
*/
template?: string | { (fieldConfiguration: IFieldConfigurationObject): string | ng.IPromise<string> };
/**
* Allows you to specify custom template manipulators for this specific field. (use defaultOptions in a
* type configuration if you want it to apply to all fields of a certain type).
*
* see http://docs.angular-formly.com/docs/field-configuration-object#templatemanipulator-object-of-arrays-of-functions
*/
templateManipulators?: ITemplateManipulators;
/**
* This is reserved for the templates. Any template-specific options go in here. Look at your specific
* template implementation to know the options required for this.
*
* see http://docs.angular-formly.com/docs/field-configuration-object#templateoptions-object
*/
templateOptions?: ITemplateOptions;
/**
* Can be set instead of type or template to use a custom html template form field. Works
* just like a directive templateUrl and uses the $templateCache
*
* see http://docs.angular-formly.com/docs/field-configuration-object#templateurl-string--function
*/
templateUrl?: string | { (fieldConfiguration: IFieldConfigurationObject): string | ng.IPromise<string> };
/**
* The type of field to be rendered. This is the recommended method
* for defining fields. Types must be pre-defined using formlyConfig.
*
* see http://docs.angular-formly.com/docs/field-configuration-object#type-string
*/
type?: string;
/**
* An object with a few useful properties mostly handy when used in combination with ng-messages
*/
validation?: {
/**
* This is set by angular-formly. This is a boolean indicating whether an error message should be shown. Because
* you generally only want to show error messages when the user has interacted with a specific field, this value
* is set to true based on this rule: field invalid && (field touched || validation.show) (with slight difference
* for pre-angular 1.3 because it doesn't have touched support).
*/
errorExistsAndShouldBeVisible?: boolean;
/**
* A map of Formly Expressions mapped to message names. This is really useful when you're using ng-messages
* like in this example.
*/
messages?: {
[key: string]: IExpresssionFunction | string;
}
/**
* A boolean you as the developer can set to specify to force options.validation.errorExistsAndShouldBeVisible
* to be set to true when there are $errors. This is useful when you're trying to call the user's attention to
* some fields for some reason.
*/
show?: boolean;
}
/**
* An object where the keys are the name of the validator and the values are Formly Expressions;
*
* Async Validation
* All function validators can return true/false/Promise. A validator passes if it returns true or a promise
* that is resolved. A validator fails if it returns false or a promise that is rejected.
*
* see http://docs.angular-formly.com/docs/field-configuration-object#validators-object
*/
validators?: {
[key: string]: string | IExpresssionFunction | IValidator;
}
/**
* This is a getter/setter function for the value that your field is representing. Useful when using getterSetter: true
* in the modelOptions (in fact, if you don't disable the ngModelAttrsTemplateManipulator that comes built-in with formly,
* it will automagically change your field's ng-model attribute to use options.value.
*
* see http://docs.angular-formly.com/docs/field-configuration-object#value-gettersetter-function
*/
value?(): any; //Getter
value?(val: any): void; //Setter
/**
* An object which has at least two properties called expression and listener. The watch.expression is added
* to the formly-form directive's scope (to allow it to run even when hide is true). You can specify a type
* ($watchCollection or $watchGroup) via the watcher.type property (defaults to $watch) and whether you want
* it to be a deep watch via the watcher.deep property (defaults to false).
*
* see http://docs.angular-formly.com/docs/field-configuration-object#watcher-objectarray-of-watches
*/
watcher?: IWatcher | IWatcher[];
/**
* This makes reference to setWrapper in formlyConfig. It is expected to be the name of the wrapper. If
* given an array, the formly field template will be wrapped by the first wrapper, then the second, then
* the third, etc. You can also specify these as part of a type (which is the recommended approach).
* Specifying this property will override the wrappers for the type for this field.
*
* http://docs.angular-formly.com/docs/field-configuration-object#wrapper-string--array-of-strings
*/
wrapper?: string | string[];
//ALL PROPERTIES BELOW ARE ADDED (So you should not be setting them yourself.)
/**
* This is the NgModelController for the field. It provides you with awesome stuff like $errors :-)
*
* see http://docs.angular-formly.com/docs/field-configuration-object#formcontrol-ngmodelcontroller
*/
formControl?: ng.IFormController | ng.IFormController[];
/**
* Will reset the field's model and the field control to the last initialValue. This is used by the
* formly-form's options.resetModel function.
*
* see http://docs.angular-formly.com/docs/field-configuration-object#resetmodel-function
*/
resetModel?: () => void;
/**
* It is not likely that you'll ever want to invoke this function. It simply runs the expressionProperties expressions.
* It is used internally and you shouldn't have to use it, but you can if you want to, and any breaking changes to the
* way it works will result in a major version change, so you can rely on its api.
*
* see http://docs.angular-formly.com/docs/field-configuration-object#runexpressions-function
*/
runExpressions?: () => void;
/**
* Will reset the field's initialValue to the current state of the model. Useful if you load the model asynchronously.
* Invoke this when the model gets set. This is used by the formly-form's options.updateInitialValue function.
*
* see http://docs.angular-formly.com/docs/field-configuration-object#updateinitialvalue-function
*/
updateInitialValue?: () => void;
}
/**
*
*
* see http://docs.angular-formly.com/docs/custom-templates#section-formlyconfig-settype-options
*/
interface ITypeOptions {
apiCheck?: { [key: string]: Function };
apiCheckFunction?: string; //'throw' or 'warn
apiCheckInstance?: any;
apiCheckOptions?: Object;
defaultOptions?: IFieldConfigurationObject | Function;
controller?: Function | string | any[];
data?: Object;
extends?: string;
link?: ng.IDirectiveLinkFn;
overwriteOk?: boolean;
name: string;
template?: Function | string;
templateUrl?: Function | string;
validateOptions?: Function;
wrapper?: string | string[];
}
interface IWrapperOptions {
apiCheck?: { [key: string]: Function };
apiCheckFunction?: string; //'throw' or 'warn
apiCheckInstance?: any;
apiCheckOptions?: Object;
overwriteOk?: boolean;
name?: string;
template?: string;
templateUrl?: string;
types?: string[];
validateOptions?: Function;
}
interface IFormlyConfig {
setType(typeOptions: ITypeOptions): void;
setWrapper(wrapperOptions: IWrapperOptions): void;
}
interface ITemplateScopeOptions {
formControl: ng.IFormController | ng.IFormController[];
templateOptions: ITemplateOptions;
validation: Object;
}
/**
* see http://docs.angular-formly.com/docs/custom-templates#templates-scope
*/
interface ITemplateScope {
options: ITemplateScopeOptions;
//Shortcut to options.formControl
fc: ng.IFormController | ng.IFormController[];
//all the fields for the form
fields: IFieldConfigurationObject[];
//the form controller the field is in
form: any;
//The object passed as options.formState to the formly-form directive. Use this to share state between fields.
formState: Object;
//The id of the field. You shouldn't have to use this.
id: string;
//The index of the field the form is on (in ng-repeat)
index: number;
//the model of the form (or the model specified by the field if it was specified).
model: Object | string;
//Shortcut to options.validation.errorExistsAndShouldBeVisible
showError: boolean;
//Shortcut to options.templateOptions
to: ITemplateOptions;
}
/**
* see http://docs.angular-formly.com/docs/formlyvalidationmessages#addtemplateoptionvaluemessage
*/
interface IValidationMessages {
addTemplateOptionValueMessage(name: string, prop: string, prefix: string, suffix: string, alternate: string): void;
addStringMessage(name: string, string: string): void;
messages: { [key: string]: ($viewValue: any, $modelValue: any, scope: ITemplateScope) => string };
}
}