It'd be awesome to choose to show the exposed filter widgets to users as a series of radios or checkboxes, rather than selects. Selects can be less intuitive and less accessible (see http://www.cs.tut.fi/~jkorpela/forms/choices.html#select-inflex for a big screed about why).

Sorry in advance if this is a feature or has been covered in some other issue; I could not find it.

Comments

momper’s picture

hello

i agree - perfect would be the possibility to choose for each filter if its checkbox or dropdown ...

1000x thanks and greetings momper

Firewolf’s picture

Especially for the cck fields single on/off checkboxes.
When I add such a field as exposed filter I get a textfield in which the user has to enter 0/1. A checkbox in that spot would be great.

Firewolf’s picture

Based on code snippets on http://drupal.org/node/84286 I created the following code which works for me.
With this code in a separate test.module the single on/off checkbox field is shown as a checkbox for the exposed filter... and working ;)
The code is perhaps not stable and usefull for everybody, but can perhaps be improved by others or integrated in other modules.

function test_expand_checkboxes($element) {
  $value = is_array($element['#value']) ? $element['#value'] : array();
  $element['#tree'] = TRUE;
  $element[] = array(
    '#type' => 'checkbox',
	'#processed' => TRUE,
    '#attributes' => $element['#attributes']);
  return $element;
}

function test_form_alter($form_id, &$form) {
if (isset($form['view']['#value']->exposed_filter)) {
  $view = $form['view']['#value'];
  foreach ($view->exposed_filter as $count => $expose) {
    if (is_numeric($count)) {
      if (!$form["filter$count"]['#options']) {
        $form["filter$count"]['#type'] = 'checkboxes';
        $form["filter$count"]['#process'] = array('test_expand_checkboxes' => array());
      }
      $form["filter$count"]['#required'] = TRUE;
    }
  }
}
}
zmove’s picture

I don't understand how to put this code.

I create a "test" folder on my module folder like that : /sites/all/modules/test

I put the php code on a test.module file in this folder.

And the module don't appear on the drupal module listing...

How to activate this code ?

zmove’s picture

Sorry I didn't understand that the code only was for checkbox CCK.

As frank van geirt said, it could be really great and really usefull if cou can choose how you want to show your exposed filter in the exposed filter himself options. Like that you can select for each filter how you want to show it. You could have 1 exposer filter in radio button, another filter in checkbox etc...

The only way I found to have checkbox instead list is here http://drupal.org/node/138374

  • The first problem is that it's a tweak of form tweaker, and if you don't want form tweaker, there is no way... :/
  • The second problem is that it transform all your exposed filter into checkbox, you cant put different type of exposed filters

If I could I would work on it, but I'm not a great developper to try something like that (or maybe to take 2 years to develop it) but I think it could be the most usefull thing you could add to view today.

Coyote’s picture

It would indeed be fantastically useful if, on a per-filter checkbox, you could decide whether to render the exposed filter as radios/checkboxes (depending on whether the "force single" box is checked, perhaps?)

nschelly’s picture

Subscribing... I'm looking for this functionality as well. I've tried stumbling around the views code to get a patch together, but I'm coming up short. I'll keep trying in the meantime, but if anyone has a good start, I'm looking.

nschelly’s picture

Version: 6.x-2.x-dev » 5.x-1.5

For those interested, I did accomplish this in part with a small module that I posted here: http://drupal.org/project/views_checkboxes
I still think it's best served by making it a per-filter option in a view, but short of that, this module satisfies my generic needs and could probably be easily expanded for more usage.
-N

EDIT: Fixed the link... sorry.

Robin Millette’s picture

zmove’s picture

View checkboxes only allow to redefine all view filter to a given format. We should be able to define that for each exposed filter when you create a view.

catch’s picture

Version: 5.x-1.5 » 6.x-2.x-dev

bumping to views 2, can't see this happening fro views 1 apart from the contrib module.

I'm fairly sure you could also do it with hook_form_alter if you need granular customisation like this for now.

freakalis’s picture

Version: 5.x-1.5 » 6.x-2.x-dev

I would also like to have checkboxes as an option per exposed filter in the View module.

storbaek’s picture

+1 for checkboxes in Views.

While, I cannot get the checkboxes for views (the module) to work for exposed filters, it's a great option. It should allow both checkboxes and fields to be checked (when multiple options are allowed).

dejbar’s picture

I also would find this of great use. It would be nice to have the option to use a series of links as well.

merlinofchaos’s picture

Status: Active » Closed (won't fix)

There are problems with checkboxes that make them ill suited to exposed filters due to the interaction of checkboxes and GET.

1) When using GET arguments, each checkbox has its own name. Thus, while using a select box you'll get "http://www.example.com?foo=1,2,3" with checkboxes the URL becomes "http://www.example.com?foo[1]=1&foo[2]=1&foo[3]=1".
2) 1) isn't that bad, but this one is: If no boxes are checked, FAPI will fill the checkboxes to the 'default' state rather than having no checkboxes filled, meaning you cannot have checkboxes defaulting to on. This is because if there are no checkboxes checked, nothing is sent in the URL; if nothing is sent, fapi doesn't see anything.

Because of these problems, I've decided to generally not uses checkboxes in place of select with exposed filters.

zmove’s picture

Hi,

Very interesting reply. What about getting checkboxes checked values with jquery and, when validating the form, transform the url in http://www.example.com?foo=1,2,3 ?

zmove

merlinofchaos’s picture

There is no way for that to degrade sanely without javascript and we do want to support the non-javascript solution as much as possible.

Andy Inman’s picture

New release of views_checkboxes module - http://drupal.org/node/273124 It's still not configurable on a per-view basis (that would be feasible but is it really necessary?). The global options have been extended such that, I think it will cater for the majority of requirements.

mattgilbert’s picture

+1 for checkboxes/subscribing

Heilong’s picture

Subscribing...

Alexander Matveev’s picture

Subscribing

SpikeX’s picture

Subscribing. Selecting options out of a list box with CTRL is so rudimentary! This needs to be a Views feature!

thebuckst0p’s picture

I solved this with a custom theme_select_as_checkboxes function, cross-posted here: http://drupal.org/node/138374#comment-2091062

mikeker’s picture

FYI: I rolled up Ben's excellent idea (see the link @23) into a simple module: Better Exposed Filters which gives you a per-filter option of using the default select box or radio buttons/checkboxes. I've tested it with Taxonomy fields, CCK fields and core node fields and would appreciate any help with additional compatibility testing or suggestions.

Thanks.

- Mike

thebuckst0p’s picture

Nice work! I note it on my blog here.

k.obrien’s picture

I just enabled this module and it works great! Thanks so much! I'm thrilled.