I am using views exposed filter.
I want to change the text -Any-
into something else.
How can I do that (without using jquery/javascript) ?
I found the solution for this. If anyone is looking for the solution can look into this example.
function MYMODULE_form_views_exposed_form_alter(&$form, &$form_state) {
//Got the Form Id by using inspect element/Firebug
if($form["#id"] == 'views-exposed-form-tutors-page'){
//field_city_tid is the Filter Identifier Key
$form['field_city_tid']['#options']["All"] = 'Desired Text';
}
}
If you use the Better Exposed Filters module you can do this using the views interface. Changed exposed form style to 'better exposed filters' and adjust the settings
The Better Exposed Filters module replaces the Views' default single- or multi-select boxes with radio buttons or checkboxes, respectively. Description fields and Select All/None links can be added to exposed filters to make for a better user experience.
You can achieve this goal via implementing hook_form_alter
Let e.g.
/**
* Implements hook_form_alter().
*/
function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'views_exposed_form' && $form_state['view']->name == 'test' && $form_state['view']->current_display == 'page_1') {
// do your alteration stuff
$form['field_city_tid']['#empty_option'] = t('All');// Or whatever you want to do
}
if ($form_id == 'views_exposed_form' && $form_state['view']->name == 'test' && $form_state['view']->current_display == 'page_2') {
// do your alteration stuff
}
}
Concrete example of an exposed Boolean filter for a view on a custom entity. Note that I had to add _value
to field names.
rsc
transactions
purchase
field_order_shipped
Actual code:
function rsc_form_views_exposed_form_alter(&$form, &$form_state)
{
if ($form['#id'] == 'views-exposed-form-transactions-purchase') {
$form['field_order_shipped_value']['#options']['All'] = 'Any';
$form['field_order_shipped_value']['#options']['1'] = 'Yes';
$form['field_order_shipped_value']['#options']['0'] = 'No';
}
}