-
Notifications
You must be signed in to change notification settings - Fork 434
/
users.forms.ts
56 lines (49 loc) · 1.57 KB
/
users.forms.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
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Form, ValidatorsEx } from '@app/shared';
import { UpdateUserDto } from './../services/users.service';
export class UserForm extends Form<FormGroup, UpdateUserDto> {
constructor(
formBuilder: FormBuilder
) {
super(formBuilder.group({
email: ['',
[
Validators.email,
Validators.required,
Validators.maxLength(100)
]
],
displayName: ['',
[
Validators.required,
Validators.maxLength(100)
]
],
password: ['',
[
Validators.required
]
],
passwordConfirm: ['',
[
ValidatorsEx.match('password', 'Passwords must be the same.')
]
],
permissions: ['']
}));
}
public load(value: any) {
if (value) {
this.form.controls['password'].setValidators(Validators.nullValidator);
} else {
this.form.controls['password'].setValidators(Validators.required);
}
super.load(value);
}
protected transformLoad(user: UpdateUserDto) {
return { ...user, permissions: user.permissions.join('\n') };
}
protected transformSubmit(value: any): UpdateUserDto {
return { ...value, permissions: value['permissions'].split('\n').filter((x: any) => !!x) };
}
}