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 !
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.
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',
),
),
);
$form_state['view']->current_display == 'page_3' || $form_state['view']->current_display == 'page_6'
please ?