-
Notifications
You must be signed in to change notification settings - Fork 11
/
ControlGroupHelper.ts
33 lines (27 loc) · 996 Bytes
/
ControlGroupHelper.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
import {ControlGroup} from 'angular2/common';
import {Model} from '../models/model';
import {Control} from 'angular2/common';
export class ControlGroupHelper {
/**
* Update control group from model
* @param controlGroup
* @param model
*/
static updateControls(controlGroup: ControlGroup, model: Model) {
model.attributeNames.forEach( (attributeName) => {
if (!!controlGroup.controls[attributeName]) {
(<Control>controlGroup.controls[attributeName]).updateValue(model[attributeName], true);
}
});
}
static setControlErrors(controlGroup: ControlGroup, field: string, errors: string[]) {
if (!!controlGroup.controls[field]) {
var errorsObject = {};
// transform array to object in order to be compatible with angular2 control group errors type
for (var i in errors) {
(<any>errorsObject)[i] = field + ' ' + errors[i];
}
(<Control>controlGroup.controls[field]).setErrors(errorsObject, true);
}
}
}