Commit d955d61f authored by M Parker's avatar M Parker Committed by Colan Schwartz
Browse files

Issue #2891276 by hmendes, mparker17, agiraud, paulmckibben, jessicacs:...

Issue #2891276 by hmendes, mparker17, agiraud, paulmckibben, jessicacs: checked, !checked don't work because states set on checkbox, radiobutton wrapper divs, not HTML input elements
parent 4033018f
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -114,6 +114,20 @@ class ConditionalFieldsFormHelper {
        continue;
      }

      // If the state is "checked" or "not checked", and the dependent form
      // field is a container (i.e.: the form field wrapper around a checkbox or
      // radio button), and there is a checkbox or radio button deeper in the
      // array, we actually need to use the (deeper) checkbox or radio button
      // because it is not possible to set a checked state on a container.
      if (count(array_intersect(['checked', '!checked'], array_keys($states))) > 0
        && $dependent_form_field['#type'] === 'container'
        && isset($dependent_form_field['widget']['value']['#type'])
        && in_array($dependent_form_field['widget']['value']['#type'], ['checkbox', 'radio'])
      ) {
        $dependent_location = array_merge($dependent_location, ['widget', 'value']);
        $dependent_form_field = $dependent_form_field['widget']['value'];
      }

      // Save the modified field back into the form.
      NestedArray::setValue($this->form, $dependent_location, $dependent_form_field);