Views Filters with Exposed Select Lists

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
jdwalling's picture

Views Filters with Exposed Select Lists

Problem: Long lists in exposed filters require control key + multi-selects which are subject to keyboard errors.

Solution: Convert select lists to scrolled check box items for specific filters (not globally)

Some Possible Approaches:
irc:drupal-support 6/30/2008
[18:30] http://drupal.org/project/views_checkboxes
[18:31] I've tried this using phptemplate_form_alter in my template.php
[18:31] http://drupal.org/node/138374#comment-545078
[18:31] http://drupal.org/node/138374 => Exposed views filter widgets as checkboxes and radio buttons => Form Tweaker, Code, normal, patch (code needs review), 3 IRC mentions
[18:32] I think this does it globally too, but that could be modified
[18:32] <_DT> ipwa_ you can't use hook_form_alter in template.php you'd need to use a module
[18:32] <_DT> template.php is for theming
[18:34] <_DT> ipwa_ I've used views filter block and done a little theming of it yes
[18:35] <_DT> ipwa_: this one can be useful: http://drupal.org/project/views_filterblock

Other approaches?

Comments

I recently did this for a module

regx's picture

The module converts cck_taxonomy fields to checkboxes and back. It was for a client project and I have not posted a generic module yet.

In a module (mymodule) in this example

function mymodule_checkboxes_to_cck_taxonomy(&$field){
  # the label disapears if the term id doesn't exist so get rid of unchecked options
  if(is_array($field['tid'])){
    foreach($field['tid'] as $key => $val){
      if(!$val){
        unset($field['tid'][$key]);
      }
    }
  }
}

function mymodule_cck_taxonomy_to_checkboxes(&$field){
  # turns cck_taxonomy $field into checkboxes
  $options = array();
    foreach($field['tid']['#options'] as $key => $val){
      if(is_array($val->option)){
        $keys = array_keys($val->option);
        $key = $keys[0];
        $val = $val->option[$key];
          $options[$key]= $val;
      }
    }
  $field['tid']['#type'] = 'checkboxes';
  $field['tid']['#options'] = $options;
  unset($field['tid']['#theme']);
}

Then in form_alter

mymodule_taxonomy_to_checkboxes($form['group_ccr_credit_info']['field_ccr_credit_marks']);

replace $form['group_ccr_credit_info']['field_ccr_credit_marks'] with your cck field name

and then in form_submit

mymodule_checkboxes_to_cck_taxonomy($form_values['field_ccr_credit_marks']);

If you want me to make a generic module for this let me know. If the project required doing this for more than one field I would have done this already.
So currently I am missing out from community code review by not having this posted and need to do it anyway!

I found this post in Google

ipwa's picture

I have managed to target theming on a specific filer, this is my code: http://drupalbin.com/2289
(I'm not using base path for my image, because bas epath is messed up in my localhost)

When I uncomment the line to try to make radio buttons (this can be changed to checkboxes) it didn't work.
I als tried the patch for the form tweaker module here: http://drupal.org/node/138374#comment-545081
but I got a white screen of death and had to remove the module.
The patch gave me this error: Hunk #1 FAILED at 3.
1 out of 2 hunks FAILED

I also tried to use the code in that patch inside my function phptemplate_views_filters($form), but that didn't work either. If anyone comes up with a solution please let me know, as I don't receive replies to this thread in my mail.

this is what I had tried from the patch's code in my template:

function phptemplate_views_filters($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"]['#multiple']) {
               $form["filter2"]['#type'] = 'radios';
               if(is_array($_GET["filter2"])){
                 foreach($_GET["filter2"] as $value){
                   $form["filter2"]['#default_value'][] = $value;
                 }
               }
             }
           }
         }
       }
}

Thanks,

Nicolas

http://nic.ipwa.net

--
Nicolas

Betterselect

ipwa's picture

I wrote an email to zohan the maintainer of formtweaker module, and he told me to stay away from that module, and he suggested to try out: http://drupal.org/project/betterselect

Its a great module!! It doesn't work for me because of the CCK issue I posted in the modules issue queue, but might help you.

--
Nicolas
http://nic.ipwa.net

--
Nicolas