6

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',
    ),
  ),
);
  • 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 '15 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 '15 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 :) – Alfred Armstrong Dec 18 '15 at 17:22
  • @AlfredArmstrong, thank you. Switching like that AFAI understood your suggestion didn't solve it. – Kojo Dec 19 '15 at 19:30
  • 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. – Alfred Armstrong Dec 20 '15 at 13:14
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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