Hi, I'm using better_exposed_filters with secondary options, but there is a very annoying usability issue: after the user submits, the secondary options field always collapses.

I would like to see that after a submit, the secondary options stays open. Can this be fixed?

#10 bef-1983960-10.patch1.17 KBtim.plunkett
None View
Members fund testing for the Drupal project. Drupal Association Learn more


Anonymous’s picture

same request for me

keesje’s picture

Ran into this problem too.
The "collapse" feature is implemented using the core form API, as supposed to.
Drawback is that there is no module-specific javascript file to patch for this.

If this is to be addressed within the module code, it should be in the "exposed_form_alter" function in "better_exposed_filters_exposed_form_plugin.inc".
$secondary['#collapsed'] is always set to TRUE. Here could be checked if there is user input in any of its containing fields.

To bypass patching you could implement this as a form_alter, checking user input to override #collapsed.
Simple example for one select filter (untested):

function mymodule_form_alter(&$form, &$form_state, $form_id){
  if($form_id == 'views_exposed_form' && isset($form['secondary'])) {
    if(isset($form['secondary']['myfilter']['#default_value']) && $form['secondary']['myfilter']['#default_value'] != 'All') {
      // Do not collapse fieldset when a value is set
      $form['secondary']['#collapsed'] = FALSE;
mikeker’s picture

Category: bug » feature

BEF should be checking all the items within the secondary menu to see if any have options selected and keep the fieldset open if there are.

Marking this as a feature request -- as always, patches are welcome!

Anonymous’s picture

sorry for my stupid questions:
- where should I put the code #2?
- mymodule_form_alter: sould I replace "mymodule" with anything else?
- myfilter: sould I replace "myfilter" with anything else?

RaF7’s picture

Following code seems to work on my installation. Not providing a patch, since I haven't tested this thorougly (and I'm not sure if there are use cases where the $_GET key is different from the filter name).

 * Implements hook_form_views_exposed_form_alter().
function mymodule_form_views_exposed_form_alter(&$form, $form_state) {
    if (isset($form['secondary'])) {
      foreach (element_children($form['secondary']) as $key) {
        if (isset($_GET[$key]) && ($_GET[$key] !== '' && $_GET[$key] !== 'All')) {
          $form['secondary']['#collapsed'] = FALSE;
Anonymous’s picture

it works perfectly, thanks.

JKingsnorth’s picture

#5 is a working workaround! Can anyone confirm whether there would be a problem in basing a patch off this approach?

mikeker’s picture

Please be sure to include AJAX-based views in addition to filters that have a default option other than "all" set. (For the second, select an option in the configure filter dialog so that option appears as the default value when you navigate to the page with no querystring params).

And report back your results! Thanks.

KerriO’s picture

#5 works for me.
Definitely seconding this as a feature request. More specifically, a set of options to select collapse behavior for secondary filters.

tim.plunkett’s picture

Issue summary: View changes
Status: Active » Needs review
1.17 KB
None View

This is technically a feature request because it never worked and never claimed to, but from a UX perspective this is a major bug.

mikeker’s picture

@tim.plunkett: Thank you for the patch. I've committed it -- you're right, this has been a major UX bug.

I would love to see the secondary options fieldset collapse when the selected options are returned to their defaults, though I suppose that's what the Reset button is for. :)

mikeker’s picture

Status: Needs review » Fixed
asgorobets’s picture

it still collapses in cases when users change their filter identifier in Views UI. I've created a separate issue for that.
#2189321: Secondary options closed after submit if filter identifier is not left default.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.