0
votes

In my site i have a view page with an exposed filter ->search terms allowing users to search using keywords.

In that search-box i have a label ( ->Enter keywords..) and it's being displayed as placeholder. On click in that box, that label is being disappeared and you can write your own keywords. If nothing is being typed by clicking somewhere else, the label (->Enter keywords..) is being appeared again. By pressing submit button all results are being displayed. That behavior is acceptable.

I need that view in whole site and i want to add a view block with the same exposed filter.

The problem is, when i press the submit button (in the view block), the label (->Enter keywords..) is being considered as the desired keyword. So no results are being displayed.

I need that label to be ignored if no keywords are being typed from users in that search-box.

Maybe helpful info:

  • On click in any of these two search-boxes, the placeholder label (->Enter keywords..) is being disappeared in both search-boxes.
  • If i enter a valid (according to my nodes) keyword the correct results are being displayed.
  • The seach in view page has no problem (the label is being ignored on submit)

This is the generated HTML for the view page:

<div id="edit-keys-wrapper" class="views-exposed-widget views-widget-filter-keys">
                  <label for="edit-keys">
            Εισάγετε λέξεις κλειδιά...          </label>
                        <div class="views-widget">
          <div class="form-item form-type-textfield form-item-keys">
 <input title="Enter the terms you wish to search for." type="text" id="edit-keys" name="keys" value="" size="15" maxlength="128" class="form-text">
</div>
        </div>
              </div>

This is the generated HTML for the view block:

<div id="edit-keys-wrapper" class="views-exposed-widget views-widget-filter-keys">
                        <div class="views-widget">
          <div class="form-item form-type-textfield form-item-keys">
 <input title="Enter the terms you wish to search for." type="text" id="edit-keys" name="keys" value="" size="15" maxlength="128" class="form-text">
</div>
        </div>
              </div>
1
Is the placeholder text implemented using the 'placeholder' attribute on the input field? Can you paste the generated HTML for the filter field?Scott Anderson

1 Answers

0
votes

If you're currently using the Placeholder module...(https://www.drupal.org/project/placeholder)

You can use HTML5 placeholder attribute instead. You could do this by altering the form via a hook and adding the attribute to the field.

e.g.

function mymodule_form_alter(&$form, $form_state, $form_id) {
  if($form_id == 'views_exposed_form') {
    $form['keys']['#attributes']['placeholder'] = $form['keys']['#attributes']['title'];
  }
}