1

I'm using

Content: Translation language (exposed)

in my code, And I Have two Options - autocomplete - dropdown

I'd like to have Checkbox, How Can I enable it?

enter image description here

I'm using Drupal 8

1
  • bef for drupal 7 may the logic will help you out Feb 8, 2016 at 13:28

2 Answers 2

3

Not sure where you're trying to do this, but if it's a node edit form, you can just change the widget to "Check boxes/radio buttons" on Manage Form Display (admin/structure/types/manage/<content_type>/form-display). Make sure the Options module is installed.

For an exposed filter in a View, say, you can use a hook_form_alter to change the #type to whatever you want; e.g.:

function YOUR_MODULE_form_views_exposed_form_alter(&$form, FormStateInterface $form_state) {
  $form['field_your_field']['#type'] = 'checkboxes';

  // If there's no user input (code not shown), rebuild the form.
  $form_state->setRebuild();
}

Only makes sense if #multiple is set to TRUE of course.

UPDATE: Added the call to setRebuild().

1

On Drupal 8.7.8 it is nearly the same.

Edit your themes/YOURTHEME/YOURTHEME.theme file and add

function YOURTHEME_form_views_exposed_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state) {
  $form['field_your_field']['#type'] = 'checkboxes';
}

The setRebuild() call breaks the functionality on my system.

field_your_field is the system name of the field you want to change, either find it by using browser development tools or the field config of your respective content type.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.