Hi,
I've written a small custom module called "Selectable Price" to make the min and max exposed filters into selectable dropdowns.
In my exposed filter for "in between" min and max integer field (field_rentpcm) values, I want to start with "No Min" and "No Max" exactly like we see on property listing sites like www.zoopla.com or www.rightmove.co.uk
But however I twist it, it keeps telling me "An illegal choice has been detected. Please contact the site administrator." and the View remains empty.
I even commented out the default value lines - still the same problem as soon as Flush all caches.
Could you please have a look at my code and tell me what I'm doing wrong?
<?php
function selectable_price_form_views_exposed_form_alter(&$form, $form_state, $form_id) {
$field_name = 'field_rentpcm';
if (empty($form_state['view']->exposed_input[$field_name])) {
$form_state['input'][$field_name] = array();
}
unset ($form[$field_name.'_value']['min']);
unset ($form[$field_name.'_value']['max']);
$price_min_options = array(
'' => 'No Min',
'100' => '100 pcm',
'200' => '200 pcm',
'300' => '300 pcm',
'400' => '400 pcm',
'500' => '500 pcm',
'600' => '600 pcm',
'700' => '700 pcm',
'800' => '800 pcm',
'900' => '900 pcm',
'1000' => '1,000 pcm',
'1250' => '1,250 pcm',
'1500' => '1,500 pcm',
);
$price_max_options = array(
'10000' => 'No Max',
'100' => '100 pcm',
'200' => '200 pcm',
'300' => '300 pcm',
'400' => '400 pcm',
'500' => '500 pcm',
'600' => '600 pcm',
'700' => '700 pcm',
'800' => '800 pcm',
'900' => '900 pcm',
'1000' => '1,000 pcm',
'1250' => '1,250 pcm',
'1500' => '1,500 pcm',
);
$form[$field_name.'_value']['min'] = array (
'#type' => 'select',
'#multiple' => false,
'#required' => false,
'#options' => $price_min_options,
// '#default_value' => 'No Min',
);
$form[$field_name.'_value']['max'] = array (
'#type' => 'select',
'#multiple' => false,
'#required' => false,
'#options' => $price_max_options,
// '#default_value' => array(array('value' => "1")),
);
}
?>
(without the final "?>" because this is a module)
I just want those texts that indicate "empty" and say "" or "-Any-", to say "No Min" and "No Max" respectively.
Thank you very much for the support!
Comments
Comment #1
dawehnerthis should be '' instead. I'm a bit confused because this is more or less common fapi behavior ...
Use '#default_value' => 10000 instead.
PS: Maybe you should stay away from the computer for some time. Once you do this things are working often much better.
Comment #2
damiankloip CreditAttribution: damiankloip commentedIs this resolved now? You should just be able to change the names of the values in the form alter if you just want to change the empty defaults.
Comment #3
MustangGB CreditAttribution: MustangGB commentedNo reply so assuming this is resolved now.