9

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',
    ),
  ),
);
12
  • Is it because you've got the optional button ticked? If you don't have that enabled then the default should be selected
    – Leigh
    Dec 18, 2015 at 16:40
  • If I tick any in the admn form, then it will show up 3 choices : any, open, and confirmed. I don't want the option any to show up nor to be default selected one ;)
    – Kojo
    Dec 18, 2015 at 16:42
  • 2
    I seem to recall there's a bug in this situation, and I also vaguely recall that it can be worked around by switching back to the single filter setting and then back to grouped again. But my memory is so uncertain I'm not offering this as an answer :) Dec 18, 2015 at 17:22
  • 1
    The other thing I'd suggest would be to export the view, edit the code then re-import it. I've worked round bugs in Views before this way. Dec 20, 2015 at 13:14
  • 1
    @harsh thanks. well I've done the form_id selection step, better said I'm looking for //you code part in order to force default radio button to be ticked ;) And why $form_state['view']->current_display == 'page_3' || $form_state['view']->current_display == 'page_6' please ?
    – Kojo
    Dec 24, 2015 at 12:28

2 Answers 2

0

Should add select="selected" for the radio widget to solve this issue.

0

You have checked the option Optional This exposed filter is optional and will have added options to allow it not to be set.

If a filter is optional nothing will be automatically checked on page load.

If you want an option in a group of radios/checkboxes to be automatically checked you need to turn off the Drupal setting in that filter that makes it optional. This way your filter will get the required HTML attribute and the form won't be able to be submitted without it.

The option you set as Default will be the one checked, if you don't have the "Optional" checked as explained above.

BEF doesn't affect this, BEF affects the look and how user interacts, but not the core functionality of how form item is set up.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.