You can easily add better classes by filter type to Views 3 exposed filters in Drupal 7. These code examples show how to do it!
The following code shows how to add the "views-widget-form-type-[TYPE]" class to the views exposed filter widget wrapper (next to ".views-exposed-widget").
The solution helps for better views filter styling.
template.php
* template_preprocess_views_exposed_form(&$vars) - views3
* #webksde#JP20082012: Add views exposed filters form element type classes to wrapper divs.
*
* Manipulates the $widget - object by adding a type attribute from field type.
* Makes the value available as class attribute in template: views-exposed-form.tpl.php
* Used there by adding "views-widget-form-type-field_type; ?>" (Line 32) next to .views-exposed-widget
*/
function esarl_theme_preprocess_views_exposed_form(&$vars) {
$form = &$vars['form'];
//dsm($form);
//dsm($vars['widgets']);
foreach ($vars['widgets'] as $id => $widget) {
// Get field type
$field_key = $form['#info'][$id]['value'];
$field_type = null;
// Default method:
if(isset($form[$field_key]['#type'])){
$field_type = $form[$field_key]['#type'];
}
// Fallbacks
if(empty($field_type)){
if(!empty($form[$field_key]['min']['#type'])){
// Is Date? (Has Min and Max?)
$field_type = $form[$field_key]['min']['#type'];
} elseif(!empty($form[$field_key]['max']['#type'])) {
// Is Date? (Has Min and Max?)
$field_type = $form[$field_key]['max']['#type'];
}
// Other fallback checks required? Add HERE!
}
if(!empty($field_type)){
// If #type is available (not for date for example).
$widget->field_type = drupal_html_class(check_plain($field_type));
$vars['widgets'][$id] = $widget;
}
}
}
?>
views-exposed-form.tpl.php, Line 32: