I have a simple form in a custom module that works well and is displaying my select as it should.
$form = Drupal::formBuilder()->getForm('DrupalefqFormFilterForm'); $form["container"] = array( 'categories' => array( '#title' => t('Select a Category'), '#type' => 'select', '#options' => array( 1 => t('Option 1'), 2 => t('Option 2'), 3 => t('Option 3'), ) ) );
I would like to change Select for Checkboxes. According to this, “Checkboxes” structure is the same as per “Select”. But when I change '#type' => 'select'
for '#type' => 'checkboxes'
there are no checkboxes created and I got the 2 following warnings:
Notice: Undefined index: #title_display in DrupalCoreRenderElementCheckboxes::preRenderCompositeFormElement() (line 20 of core/lib/Drupal/Core/Render/Element/CompositeFormElementTrait.php). Notice: Undefined index: #id in DrupalCoreRenderElementCheckboxes::preRenderCompositeFormElement() (line 30 of core/lib/Drupal/Core/Render/Element/CompositeFormElementTrait.php).
Adding these in an array makes the notice messages disappear but the checkboxes are still not showing.
Any idea of what’s going on ?
Sponsored by SupremePR