I'm attempting to change the placeholder text for the origin field in the proximity filter. Here is what I have so far - it just doesn't seem to be doing the job. What is the obvious thing I am missing?

  	if($form_id == 'views_exposed_form') {
  		$view = $form_state['view'];
        if ($view->name == 'omapx' && $view->current_display == 'page_3') {
            $form['field_geofield_distance_origin']['#attributes']['placeholder'] = t('Missoula, MT');
        }

  	}

Comments

bisonbleu’s picture

@stopshinal, did you find a solution?

I also would like to set a placeholder text in the proximity search field e.g. "Enter zip code or street address here...".

Any suggestions on how best to do this?

bisonbleu’s picture

Title: Change default/placeholder text for origin using Hook » How to set a placeholder text for the proximity search field?

Better title (I hope).

tpaddy’s picture

I created a small custom module and used the following code to add placeholder text. This is the comment that helped me figure out how to modify the exposed filter form

<?php
/**
 * Implements hook_element_info_alter()
 * Add additional (!) custom process function
 */
function YOURMODULE_element_info_alter(&$type) {
  if (isset($type['geofield_proximity']['#process'])) {
    $type['geofield_proximity']['#process'][] = 'YOURMODULE_proximity_element_process';
  }
}
/*
 * Alter geofield views exposed form, add placeholder text to search field
 */
function YOURMODULE_proximity_element_process($element, &$form_state, $form) {
  $element['origin']['#attributes']['placeholder'] = t('Enter zip code or street address here...');
  return $element;
}

Hope that helps!

quercus020’s picture

This works a treat. Thanks for posting.

malcomio’s picture

Status: Active » Fixed

Yes - works great. In case anyone else is dopey like me and misses it, the process function does not pass $element by reference, so you need to have the return $element line at the end.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

RumpledElf’s picture

You can also do this:

function hook_form_views_exposed_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  ...
  $form['your geo origin field']['#origin_options']['#attributes']['placeholder'] = your text here;
...
 }