@@ -12,7 +12,7 @@ class Activities extends BaseComponent {
12
12
activities ?: SendInnAktivitet [ ] = undefined ;
13
13
activitiesError ?: string ;
14
14
defaultActivity = {
15
- value : 'ingenAktivitet' ,
15
+ activity : { aktivitetId : 'ingenAktivitet' , maalgruppe : '' , periode : { fom : '' , tom : '' } } ,
16
16
text : this . t ( 'Jeg får ikke opp noen aktiviteter her som stemmer med det jeg vil søke om' ) ,
17
17
} ;
18
18
@@ -34,8 +34,16 @@ class Activities extends BaseComponent {
34
34
return activitiesBuilder ( ) ;
35
35
}
36
36
37
+ // The radio/checkbox values are simple strings, but the whole activity object is stored in the submission
37
38
changeHandler ( value : string , opts : { modified : boolean } ) {
38
- super . updateValue ( value , opts ) ;
39
+ if ( value === 'ingenAktivitet' ) {
40
+ super . updateValue ( this . defaultActivity . activity , opts ) ;
41
+ } else {
42
+ const activity = this . activities ?. find ( ( x ) => x . aktivitetId === value ) ;
43
+ if ( activity ) {
44
+ super . updateValue ( activity , opts ) ;
45
+ }
46
+ }
39
47
this . rerender ( ) ;
40
48
}
41
49
@@ -49,8 +57,6 @@ class Activities extends BaseComponent {
49
57
const appConfig = this . getAppConfig ( ) ;
50
58
const isLoggedIn = this . getIsLoggedIn ( ) ;
51
59
52
- console . log ( 'appConfig' , appConfig ) ;
53
-
54
60
if ( ! this . loadFinished && appConfig ?. app === 'fyllut' && isLoggedIn === true ) {
55
61
this . isLoading = true ;
56
62
getActivities ( appConfig )
@@ -71,6 +77,14 @@ class Activities extends BaseComponent {
71
77
}
72
78
}
73
79
80
+ mapActivity ( activity : SendInnAktivitet ) {
81
+ return {
82
+ aktivitetId : activity . aktivitetId ,
83
+ maalgruppe : activity . maalgruppe ,
84
+ periode : activity . periode ,
85
+ } ;
86
+ }
87
+
74
88
renderReact ( element ) {
75
89
this . getActivities ( ) ;
76
90
@@ -79,14 +93,14 @@ class Activities extends BaseComponent {
79
93
< CheckboxGroup
80
94
id = { this . getId ( ) }
81
95
legend = { this . getLabel ( ) }
82
- value = { this . getValue ( ) }
96
+ value = { this . getValue ( ) ?. aktivitetId ?? '' }
83
97
onChange = { ( values ) => this . changeHandler ( values [ 0 ] , { modified : true } ) }
84
98
ref = { ( ref ) => this . setReactInstance ( ref ) }
85
99
description = { this . getDescription ( ) }
86
100
className = { this . getClassName ( ) }
87
101
error = { this . getError ( ) }
88
102
>
89
- < Checkbox value = { this . defaultActivity . value } ref = { ( ref ) => ( this . lastRef = ref ) } >
103
+ < Checkbox value = { this . defaultActivity . activity . aktivitetId } ref = { ( ref ) => ( this . lastRef = ref ) } >
90
104
{ this . defaultActivity . text }
91
105
</ Checkbox >
92
106
</ CheckboxGroup >
@@ -98,7 +112,7 @@ class Activities extends BaseComponent {
98
112
< RadioGroup
99
113
id = { this . getId ( ) }
100
114
legend = { this . getLabel ( ) }
101
- value = { this . getValue ( ) }
115
+ value = { this . getValue ( ) ?. aktivitetId ?? '' }
102
116
onChange = { ( value ) => this . changeHandler ( value , { modified : true } ) }
103
117
ref = { ( ref ) => this . setReactInstance ( ref ) }
104
118
description = { this . getDescription ( ) }
@@ -118,7 +132,7 @@ class Activities extends BaseComponent {
118
132
</ Radio >
119
133
) ;
120
134
} ) }
121
- < Radio value = { this . defaultActivity . value } > { this . defaultActivity . text } </ Radio >
135
+ < Radio value = { this . defaultActivity . activity . aktivitetId } > { this . defaultActivity . text } </ Radio >
122
136
</ RadioGroup >
123
137
) ;
124
138
} ;
0 commit comments