Hi, I'm already succesfully using Hint on search and login forms. Now I'd like to enable it in exposed filter forms of my views.

I tried this code in a new module "filter_hint":

function filter_hint_form_alter(&$form, &$form_state, $form_id) {
  if($form_id == 'views_exposed_form'){
    if (isset($form['#info'])) {
      foreach ($form['#info'] as &$form_element) {
        if (isset($form_element['label'])) {
          $form_element['#hint'] = $form_element['label'];
          unset($form_element['label']);
        }
      }
    }
  }
}

All I obtain is that labels disappear (becouse of unset), but hint is not displayed, the hidden input is not created and there's no "hint" class in text inputs.

What am I missing?

Comments

nessunluogo’s picture

Got it!
I noticed that exposed filter's forms separate the information part (into the [#info] branch of the form array) and the settings (outside).

This is the code where I use an alternative solution to hints for select elements, renaming the "All" option with the label text.

It's still raw and may not work, but I hope this could help someone.

function filter_hint_form_alter(&$form, &$form_state, $form_id) {
  if($form_id == 'views_exposed_form'){
    if (isset($form['#info'])) {
      foreach ($form['#info'] as &$form_info) {
        $element_settings = &$form[$form_info['value']];
        if ($element_settings['#type'] == 'textfield') {
          // textfield: adds the hint and disables the label
          $element_settings['#hint'] = $form_info['label'];
          $form[$form_info['value']]['#hint'] = $form_info['label'];
          unset($form_info['label']);
        } elseif ($element_settings['#type'] == 'select') {
          // select: renames the "All" option and disables the label
          if (isset($element_settings['#options']['All']))
          $element_settings['#options']['All'] = '- ' . $form_info['label'] . ' -';
          unset($form_info['label']);
        }
      }
    }
  }
}