Use check/radios only when number of choices is small
netgenius - March 28, 2008 - 14:17
| Project: | Views Checkboxes |
| Version: | 5.x-3.1 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | netgenius |
| Status: | closed |
Description
Hi, nice module, but rather lacking configurability as I'm sure you recognise. I guess this shouldn't be to difficult - I suggest:
if (number_of_choices < limit)
display_as_checkboxes
else
display_as_normal_list
.. it would be nice for the limit to be configurable, but as a quick hack it could be hard-coded, perhaps 10? Am I right in thinking that a line or two of php could add this feature? (I haven't looked at your code yet, but I'm willing to try creating a patch if anybody else would be interested.)

#1
Well, I've just done a mod and it seems to work. One line of code :)
After the existing comment:
//Start looping through through all exposed filters
Add the line:
if (count($form['filter'.$count]['#options']) > 5) continue;
... then checkboxes/radios will be used if the number of items in the select list is up to 5, but if more than 5 you get a select-box (the standard behaviour.)
Since I'm in there now, I'm going to try to add this limit as a configurable option, and maybe some other stuff. I've never played with any of the Drupal APIs before, so this is a learning exercise for me.
#2
Now added configurable "limit" as described above.
Other features added:
* When select lists are being used, optionally set the number of items displayed (configurable)
* When using that feature, automatically increase the size by one if that would then display the whole list.
Updated help text to suit the above features.
Updated uninstall process to delete the configurable options which I've added.
Since I'm not familiar with the Drupal CVS procedures, I'm posting my updates here (attached.) NB: This was based on the current release - views_checkboxes-5.x-3.1 - the attached tgz contains only the .module and .install files - copy them over an existing file set.
This has been minimally tested and seems to work ok. Hope it's of use to someone.
#3
Now in new dev release 5.x-4.x-dev