@@ -114,18 +114,29 @@ function helfi_react_search_field_widget_single_element_paragraphs_form_alter(ar
114114 return;
115115 }
116116
117- $type_select = ':input[name="' . $context['items']->getName() . '[' . $element['#delta'] . '][subform][field_event_list_type]"]';
118-
117+ $select = fn (string $prefix) => ':input[name="' . $context['items']->getName() . '[' . $element['#delta'] . '][subform]' . $prefix . '"]';
119118 $states = [
120- 'field_event_list_category_event' => 'hobbies',
121- 'field_event_list_category_hobby' => 'events',
119+ 'field_event_list_category_event' => [
120+ 'state' => 'invisible',
121+ 'condition' => [$select('[field_event_list_type]') => ['value' => 'hobbies']],
122+ ],
123+ 'field_event_list_category_hobby' => [
124+ 'state' => 'invisible',
125+ 'condition' => [$select('[field_event_list_type]') => ['value' => 'events']],
126+ ],
127+ 'field_event_location' => [
128+ 'state' => 'disabled',
129+ 'condition' => [$select('[field_remote_events][value]') => ['checked' => TRUE]],
130+ ],
131+ 'field_remote_events' => [
132+ 'state' => 'disabled',
133+ 'condition' => [$select('[field_event_location][value]') => ['checked' => TRUE]],
134+ ],
122135 ];
123136
124- foreach ($states as $field => $ condition) {
137+ foreach ($states as $field => ['state' => $state, ' condition' => $condition] ) {
125138 $element['subform'][$field]['#states'] = [
126- 'invisible' => [
127- [$type_select => ['value' => $condition]],
128- ],
139+ $state => [$condition],
129140 ];
130141 }
131142}
0 commit comments