I have a view that is using the module 'views between dates filter' https://www.drupal.org/project/views_between_dates_filter as a secondary option. This provides start and end date fields.

When I submit the search and there with no search terms and the secondary options closed the secondary options are open when displaying the results.

This appears to be in the function 'exposed_form_alter' in 'better_exposed_filters_exposed_form_plugin.inc', in particular the following code.

        if (!empty($exposed_input[$filter->options['expose']['identifier']]) && $settings[$label]['more_options']['is_secondary']) {
          $secondary_collapse = FALSE;
          break;
        }

It looks to me like the problem is caused by $exposed_input[$filter->options['expose']['identifier']] not being empty when no values have been submitted because unlike a normal filter it contains an array with two values and .

Instead of being empty the contents of $exposed_input[$filter->options['expose']['identifier']] looks to be as follows

field_date_value (Array, 2 elements)
--min (Array, 1 element)
----date (String, 0 characters )
--max (Array, 1 element)
----date (String, 0 characters )

I've also checked dates with an equals operator and this also fails in a similar way. In this case the value of $exposed_input[$filter->options['expose']['identifier']] is

field_date_value (Array, 1 element)
--value (Array, 1 element)
----date (String, 0 characters )

Would you be happy looking at adding a check for a date filter?

Comments

Ollie222’s picture

I'm not setup for rolling this as a patch or if this is the most generic way of doing this however changing the following code looks to fix the problem for me.

Old code

      foreach ($this->display->handler->get_handlers('filter') as $label => $filter) {
        if (!$filter->options['exposed']) {
          continue;
        }
        if (!empty($exposed_input[$filter->options['expose']['identifier']]) && $settings[$label]['more_options']['is_secondary']) {
          $secondary_collapse = FALSE;
          break;
        }
      }

New code

      foreach ($this->display->handler->get_handlers('filter') as $label => $filter) {
        if (!$filter->options['exposed']) {
          continue;
        }
        if($settings[$label]['more_options']['is_secondary']) {
          if(!empty($filter->definition['is date'])) {
            switch (true) {
              case (!empty($exposed_input[$filter->options['expose']['identifier']]['value']['date'])) :
              case (!empty($exposed_input[$filter->options['expose']['identifier']]['min']['date'])) :
              case (!empty($exposed_input[$filter->options['expose']['identifier']]['max']['date'])) :
                $secondary_collapse = FALSE;
                break 2;
            }
          }
          else {
            if (!empty($exposed_input[$filter->options['expose']['identifier']]) && $settings[$label]['more_options']['is_secondary']) {
              $secondary_collapse = FALSE;
              break;
            }  
          }
        }
      }
rodpal’s picture

That didn't work form me. This is what I ended up doing:

				if (!empty($exposed_input[$filter->options['expose']['identifier']]) && $settings[$label]['more_options']['is_secondary']) {
					if (is_array($exposed_input[$filter->options['expose']['identifier']])) {
						if (!empty($exposed_input[$filter->options['expose']['identifier']]['date'])) {
							$secondary_collapse = FALSE;
							break;
						}
					} 
					else {
						$secondary_collapse = FALSE;
						break;
					}
        }
cimo75’s picture

Same problem here .

Neslee Canil Pinto’s picture

Status: Active » Closed (won't fix)

Hi, there will be no more future development for 7.x branch. If you see this issue in 8.x, feel free to file an issue. Closing this as Closed(wont fix).