1
1
import { TypedForm , FormOption } from '@devmx/shared-ui-global/forms' ;
2
- import { FormControl , FormGroup , Validators } from '@angular/forms' ;
2
+ import {
3
+ FormControl ,
4
+ FormGroup ,
5
+ ValidationErrors ,
6
+ Validators ,
7
+ } from '@angular/forms' ;
3
8
import { EventPresentationsForm } from './event-presentation' ;
4
9
import { DURATION_TIMES } from '@devmx/shared-util-data' ;
5
10
import { EventLeadersForm } from './event-leader' ;
@@ -25,6 +30,10 @@ export class EventForm extends FormGroup<TypedForm<EditableEvent>> {
25
30
static date = addDays ( new Date ( ) , 10 ) ;
26
31
27
32
constructor ( ) {
33
+ EventForm . date . setHours ( 19 ) ;
34
+ EventForm . date . setMinutes ( 0 ) ;
35
+ EventForm . date . setSeconds ( 0 ) ;
36
+
28
37
super ( {
29
38
id : new FormControl ( '' , {
30
39
nonNullable : true ,
@@ -41,13 +50,13 @@ export class EventForm extends FormGroup<TypedForm<EditableEvent>> {
41
50
updateOn : 'blur' ,
42
51
} ) ,
43
52
44
- time : new FormControl ( '' , {
45
- nonNullable : true ,
46
- validators : [ Validators . required ] ,
47
- } ) ,
53
+ // time: new FormControl('', {
54
+ // nonNullable: true
55
+ // }),
48
56
49
57
duration : new FormControl ( '2h' , {
50
58
nonNullable : true ,
59
+ validators : [ Validators . required ] ,
51
60
} ) ,
52
61
53
62
maxAttendees : new FormControl ( 0 , {
@@ -56,6 +65,7 @@ export class EventForm extends FormGroup<TypedForm<EditableEvent>> {
56
65
57
66
description : new FormControl ( '' , {
58
67
nonNullable : true ,
68
+ validators : [ Validators . required ] ,
59
69
} ) ,
60
70
61
71
presentations : new EventPresentationsForm ( ) ,
@@ -64,6 +74,7 @@ export class EventForm extends FormGroup<TypedForm<EditableEvent>> {
64
74
65
75
format : new FormControl ( '' , {
66
76
nonNullable : true ,
77
+ validators : [ Validators . required ] ,
67
78
} ) ,
68
79
69
80
address : new FormControl ( '' , {
@@ -115,19 +126,43 @@ export class EventForm extends FormGroup<TypedForm<EditableEvent>> {
115
126
}
116
127
117
128
onFormatChange ( format = '' ) {
129
+ if ( ! this . controls . address || ! this . controls . link ) return ;
130
+
118
131
if ( format === 'in-person' ) {
119
- this . controls . address ?. enable ( ) ;
120
- this . controls . link ?. disable ( ) ;
132
+ this . controls . address . enable ( ) ;
133
+ this . controls . address . addValidators ( Validators . required ) ;
134
+
135
+ this . controls . link . disable ( ) ;
136
+ this . controls . link . removeValidators ( Validators . required ) ;
121
137
}
122
138
123
139
if ( format === 'online' ) {
124
- this . controls . address ?. disable ( ) ;
125
- this . controls . link ?. enable ( ) ;
140
+ this . controls . address . disable ( ) ;
141
+ this . controls . address . removeValidators ( Validators . required ) ;
142
+
143
+ this . controls . link . enable ( ) ;
144
+ this . controls . address . addValidators ( Validators . required ) ;
126
145
}
127
146
128
147
if ( format === 'mixed' ) {
129
- this . controls . link ?. enable ( ) ;
130
- this . controls . address ?. enable ( ) ;
148
+ this . controls . link . enable ( ) ;
149
+ this . controls . link . addValidators ( Validators . required ) ;
150
+
151
+ this . controls . address . enable ( ) ;
152
+ this . controls . address . addValidators ( Validators . required ) ;
131
153
}
154
+
155
+ this . updateValueAndValidity ( { onlySelf : true } ) ;
156
+ }
157
+
158
+ getErrors ( ) {
159
+ const errors = { } as Record < string , ValidationErrors | null > ;
160
+
161
+ for ( const key in this . controls ) {
162
+ const k = key as keyof TypedForm < EditableEvent > ;
163
+ errors [ key ] = this . controls [ k ] ?. errors ?? null ;
164
+ }
165
+
166
+ return errors ;
132
167
}
133
168
}
0 commit comments