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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

z.stolar’s picture

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.

Jody Lynn’s picture

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.

  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>';
        }
      }
} 
z.stolar’s picture

Thanks Lynn, I'll take a look at it and I'll try to integrate it into formtweaker.

z.stolar’s picture

Version: 5.x-1.x-dev » 5.x-1.0
Component: User interface » Code
Assigned: Unassigned » z.stolar
Category: support » feature
Status: Active » Needs review
FileSize
2.57 KB

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.

z.stolar’s picture

Title: Exposed taxonomy filter widgets in views?? » Exposed views filter widgets as checkboxes and radio buttons
FileSize
2.53 KB

This patch shortens the former one, and adds the checkboxes/radio buttons capability to other than taxonomy widgets.

dpangier’s picture

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]))
z.stolar’s picture

Yeah, I just ran into the same issue as well.
My solution was to check the first value for the ALL option:

<?php
if(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.

skor’s picture

Subscribing

scottrigby’s picture

subscibe - thx

nschelly’s picture

subscribing...
-N

z.stolar’s picture

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?

scottrigby’s picture

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!

momper’s picture

subscribing

z.stolar’s picture

I think it should be discussed in the other module's issue queue.

nschelly’s picture

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

doublejosh’s picture

Here is how I accomplished this in Views2. If you turn on AJAX the form will refresh the filter in place when clicking Go!!!

function custom_module_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'views_exposed_form') {
    $exposed_views = array('post_stream'); // KEEP IN MIND THIS IS AN ARRAY... SO YOU CAN DO MORE!
    if (in_array($form_state['view']->name, $exposed_views)) {

    //drupal_set_message('<pre>'.print_r($form_state['view']->display['default']->handler->options['filters'],1).'</pre>');
    //drupal_set_message('<pre>'.print_r($form,1).'</pre>');

    $form['type']['#options']['All']= 'All';
    $form['type']['#options']['article']= 'Editorial';
    $form['type']['#options']['feed_item']= 'Outside Source';
    $form['type']['#options']['post']= 'Member Post';
    
    $form['submit']['#value']= 'Go';
    
    $form['type']['#type']= 'radios'; // <--- HERE IS THE RADIO SWITCHEROO

    }
  }
}

This is fairly one off, but can get the job done.

I have had a problem with the pager though :(

peter-boeren’s picture

I'm working on a module called Views filter pack and it work with views 2. My solution is not with much fancy Ajax, but you can alter the exposed selects to radio-buttons or even check boxes. At this point only the filters from user, node, comment and taxonomy are supported. The filters for files are on the roadmap and so is CCK support.

czeky’s picture

subscribing

thebuckst0p’s picture

I worked out a solution to this using a custom theme function for the select field. Details @ http://echodittolabs.org/blog/2009/09/how-make-views-exposed-filter-dropdown-appear-checkboxes.

tevih’s picture

I don't understand where to put this.

mikeker’s picture

I just contributed a module similar to the solution @19: Better Exposed Filters. Sorry, only available for D6.

I was having problems with Views Filter Pack not working with multiple exposed filters and Ben's theme-layer suggestion (see the link @19) was an elegant solution.

Hope that helps.

- Mike

doublejosh’s picture

Had a related issue with the promoted to front page exposed filter. Solved here: http://drupal.org/node/549180#comment-3795560