Grouped Exposed filters radio buttons : one in two no value ticked. How to programatically force default button be ticked?

Some exposed filters (radio buttons) aren’t systematically ticked when a view is displayed, causing an “An illegal choice has been detected. Please contact admin…” error message and No result found.

Moreover, refreshing the same view, or surfing between similar views with another contextual filter value (taxonomy term ID) : one in two the button is ticked, the other not ! enter image description here

Ticking any radio button once the view is loaded gives correct results.

Errors reported :

  • Warning : Illegal offset type in isset or empty dans convert_exposed_input() (line 1165 of views/handlers/views_handler_filter.inc).
  • Illegal choice 0 in field_statut_depart_value element.

EDIT : I did put below as many details as I could find to illustrate the problem, but after searching and searching, basically the question is : since I can’t find why such behaviour, nor why this is always the same value which is loaded by default, whichever setup I try : How can I alter the form and ensure the default button is ticked on page loading.

This filter filters a field which values can be “Open, Almost confirmed, Confirmed, Full, Closed”, and I need to group the filter values :

  • 1=> Any value excepting Closed, selected by default
  • 2=> Almost confirmed or Confirmed

I played around with Grouped filters and BEF, and achieved the correct radio buttons display with at least 2 different setups. This is the last setup I tried.

enter image description here

I tried then to alter the form :

function MODULE_form_alter(&$form, &$form_state, $form_id) {   if($form['#id']=='views-exposed-form-my-form'){     $form['field_status_depart_value']['#default_value'] = 1;     $form['field_status_depart_value']['#required'] = TRUE;     //dpm($form);   } } 

I could hide the error message with $form['field_status_depart_value']['#validated'] = TRUE; . It seems to be solving also the view returning empty result one in two… but now the result are filtered with one or another filter value, while the customer does not know it !

I tried without success to change the UI setup in many manners : with or without ajax, with or without BEF overwriting, optional or not, remember or not.. Same if I set to default select list, the exposed filter value toggles from one to the other at each page refresh.

After night & day fighting with that, I would feel really better to get some help, my most wished Christmas present ! Thanks a lot !

EDIT : this is the relevant parts of code export.

$handler->display->display_options['exposed_form']['options']['bef'] = array(  'field_status_depart_value' => array(     'bef_format' => 'bef',     'more_options' => array(       'bef_select_all_none' => 0,       'bef_collapsible' => 0,       'is_secondary' => 0,       'any_label' => '',       'bef_filter_description' => '',       'tokens' => array(         'available' => array(           0 => 'global_types',         ),       ),       'rewrite' => array(         'filter_rewrite_values' => '',       ),     ),   ), //...  /* Critère de filtrage: Commerce Product : Statut (field_status_depart) */ //RELEVANT LINES $handler->display->display_options['filters']['field_status_depart_value']['value'] = array(   1 => '1',   2 => '2', ); $handler->display->display_options['filters']['field_status_depart_value']['expose']['multiple'] = TRUE; $handler->display->display_options['filters']['field_status_depart_value']['is_grouped'] = TRUE; $handler->display->display_options['filters']['field_status_depart_value']['group_info']['remember'] = 1; $handler->display->display_options['filters']['field_status_depart_value']['group_info']['default_group'] = '1'; $handler->display->display_options['filters']['field_status_depart_value']['group_info']['group_items'] = array(   1 => array(     'title' => 'Opened',     'operator' => 'or',     'value' => array(       0 => '0',       1 => '1',       2 => '2',       3 => '3',     ),   ),   2 => array(     'title' => Confirmed or almost confirmed',     'operator' => 'or',     'value' => array(       1 => '1',       2 => '2',     ),   ), ); 
This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

Grouped Exposed filters radio buttons : one in two no value ticked. How to programatically force default button be ticked?

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.