I know how to use conditions with Form API for fields like textfield, checkbox etc.
For example, showing or hiding a field when a checkbox is checked:
$form['lorem'] = [ '#type' => 'checkbox', '#attributes' => [ 'name' => 'field_lorem', ] ]; $form['ipsum'] = [ '#type' => 'checkbox', '#states' => [ 'visible' => [ ':input[name="field_lorem"]' => ['checked' => true] ], ], ];
However, I can’t manage to do it with a field type checkboxes:
// This code does not work $form['lorem'] = [ '#type' => 'checkbox', '#attributes' => [ 'name' => 'field_lorem', ] ]; // options $options = [ 'test_1' => 'Test 1', 'test_2' => 'Test 2', ]; $form['ipsum'] = [ '#type' => 'checkboxes', '#options' => $options, '#states' => [ 'visible' => [ ':input[name="field_lorem"]' => array('checked' => true) ], // Ideally, I would like to have all the checkboxes checked but the problem is mainly at the state level 'checked' => [ ':input[name="field_lorem"]' => ['checked' => TRUE], ], ], ];
I can do it with custom JS but I ideally wanted to do it with the form API.
What #states property do I need to achieve this ?