Exposed views filter widgets as checkboxes and radio buttons
jasontanner - April 22, 2007 - 22:43
| Project: | Form Tweaker |
| Version: | 5.x-1.0 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | z.stolar |
| Status: | patch (code needs review) |
Description
Hi,
While reading this thread here: http://drupal.org/node/84286 I spotted a comment indicating that formstweaker might be extended to support modifying the exposed taxonomy filter widgets on views so that they appear as checkboxes/radios.
Has any progress been made in doing this ? Or does the current version do it and I'm simply being an idiot and not spotting how to enable it.
Regards
Jason

#1
I am also interested in such a solution and I'm currently researching towards it.
Since I was made co-maintainer of this module, I'll try to supply a new version of it, once I have a patch or something, or once someone else will supply one.
#2
This code is rather a mess, but it is working for me to replace exposed filter mulitple selects with checkboxes. I use it inside a hook_form_alter. Maybe it can help towards writting something more solid.
<?php
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"]['#multiple']) {
$form["filter$count"]['#type'] = 'checkboxes';
$options = array();
foreach($form["filter$count"]['#options'] as $option){
$option = $option->option;
if(is_array($option)){
$key = implode('',array_keys($option));
$option = implode('', $option);
$options[$key] = $option;
}
}
$form["filter$count"]['#options'] = $options;
}
unset($form["filter$count"]['#theme']);
unset($form["filter$count"]['#default_value']);
$form["filter$count"]['#prefix'] = '<div class="exposed-filters">';
$form["filter$count"]['#suffix'] = '</div>';
}
}
}
?>
#3
Thanks Lynn, I'll take a look at it and I'll try to integrate it into formtweaker.
#4
This patch uses a development of what Lynn sent, to turn views filters into checkboxes and radio buttons.
It works in my environment, and I'd like to know if it works for you too.
TODO:
1. Use formtweaker's helper functions to modify the selects into checkboxes (currently it is all done inside form_alter).
2. Add a checkbox to views' exposed filters interface to select whether the filter should be rendered as select or as checkboxes.
I would also appreciate comments about the quality of the patch itself, as I am not very experienced with patching etc.
#5
This patch shortens the former one, and adds the checkboxes/radio buttons capability to other than taxonomy widgets.
#6
The line
if(isobject($form["filter$count"]['#options'][0]))does not work correctly with taxonomies that don't return an item with a key of "0". I suggest:$optvalues = array_values($form["filter$count"]['#options']);if(isobject($optvalues[0]))
#7
Yeah, I just ran into the same issue as well.
My solution was to check the first value for the ALL option:
<?phpif(isset($form["filter$count"]['#options']['**ALL**'])){
// We dont need the ALL checkbox.drop it.
array_shift($form["filter$count"]['#options']);
};
?>
It seems that your solution is better, cleaner, only the function name should be is_object (with an underscore).
I'll integrate it into CVS.
In any case, there is still one important thing to do before we create a new release with this feature, and that is to add the option in views exposed filters section. We need to let the user decide when to use checkboxes and when not to.
#8
Subscribing
#9
subscibe - thx
#10
subscribing...
-N
#11
In the new 5.x-2.0 release I didn't include the views filters since we still hadn't have a way to decide on which filters exactly the form is to be tweaked or not.
Meanwhile, a new module has appeared which is doing exactly that (I haven't tested it yet): http://drupal.org/project/views_checkboxes
I see that it belongs to nschelly who subscribed here a while ago :-) .
@nschelly - Do you think it answers the needs here, and do you want to keep the modules apart or combine them?
#12
Thanks Neil & Zohar --
This seems to be a good solution, but there is an error that's happening. I would try to troubleshoot it, but my php skills are pretty larval.
Someone else already entered the issue and I commented here: http://drupal.org/node/192117#comment-630708
If anyone knows how to solve this (hopefully minor) issue, that would be great!
#13
subscribing
#14
I think it should be discussed in the other module's issue queue.
#15
I will work on the errors in my own module, but I do still think the best place for this feature would be in this module. This module though was a little more complex than for me to presume knowing how you'd want to structure a fix.
-N