I haven't done much in the way of styling our new proximity widget. It desperately needs it. Specifically, we should shorten the lengths of our text fields via css, ensure everything gets displayed inline, and come up with a sane way to render our lat/lon widget inline, probably by hiding/not rendering the fieldset around our two inputs.

CommentFileSizeAuthor
#12 geosrch.png6.86 KBfehin
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

welly’s picture

What would be great is if the distance widget could be defined as a select box (or textfield). Unless there's a hook that will allow me to do this?

welly’s picture

Category: task » support

Just further to this, I've tried styling the widget using theme_geofield_proximity as follows:

function lgnsw_geofield_proximity($vars) {
  $element = $vars['element'];

  $options = array(
    '9999' => 'All',
    '10' => '10 km',
    '25' => '25 km',
    '50' => '50 km',
    '100' => '100 km', 
    '250' => '250 km', 
    '500' => '500 km', 
  );

  $element['distance']['#type'] = 'select';
  $element['distance']['#options'] = $options;
  $element['distance']['#multiple'] = false;
  $element['distance']['#size'] = 1;
  $element['distance']['#weight'] = 10;


  $attributes = !empty($element['#wrapper_attributes']) ? $element['#wrapper_attributes'] : array('class' => array());
  $attributes['class'][] = 'geofield-proximity-field-wrapper';
  $attributes['class'][] = 'clearfix';

  $wrapper_attributes = array();
  $wrapper_attributes['class'][] = 'clearfix';

  if (isset($element['#children']))
    $element['#children'] = '<div id="' . $element['#id'] . '" ' . drupal_attributes($wrapper_attributes) . '>' . $element['#children'] . '</div>';

  $output = '<div ' . drupal_attributes($attributes) . '>' . theme('form_element', $element) . '</div>';

  return $output;
}

However, I'm not having much joy in the textfield being turned into a select field. Any advice?

Thanks

caktux’s picture

/**
 * Implements hook_element_info_alter().
 */
function MODULE_element_info_alter(&$type) {
  if (isset($type['geofield_proximity'])) {
    $type['geofield_proximity']['#process'][] = 'MODULE_proximity_element_process';
  }
}

function MODULE_proximity_element_process($element, &$form_state, $form) {
  $options = array(
    '5' => '5 km',
    '10' => '10 km',
    '25' => '25 km',
    '50' => '50 km',
    '100' => '100 km',
  );

  $element['distance']['#type'] = 'select';
  $element['distance']['#options'] = $options;
  $element['distance']['#multiple'] = false;
  
  $element['unit']['#type'] = 'hidden';
  $element['unit']['#default_value'] = GEOFIELD_KILOMETERS; // 6371

  return $element;
}
Jason Dean’s picture

Hey thanks caktux - saved my day :)

dave.erwin’s picture

Issue summary: View changes

yes, that code was a lifesaver, I needed to rearrange the distance and origin and add some labels as well

function MODULE_proximity_element_process($element, &$form_state, $form) {
  $options = array(
    '5' => '5 mi',
    '10' => '10 mi',
    '25' => '25 mi',
    '50' => '50 mi',
    '100' => '100 mi',
  );

  $element['distance']['#type'] = 'select';
  $element['distance']['#options'] = $options;
  $element['distance']['#multiple'] = FALSE;
  $element['distance']['#title_display'] = 'before';
  $element['distance']['#title'] = t('Distance from Zip');

  $element['unit']['#type'] = 'hidden';
  $element['unit']['#default_value'] = GEOFIELD_MILES;

  // Remove the "from" text.
  $element['origin']['#prefix'] = '';
  $element['origin']['#title_display'] = 'before';
  $element['origin']['#title'] = t('Zip Code');
  $element['origin']['#weight'] = -100;

  return $element;
}
sonixax’s picture

Hi,
Is it possible to use Combo-Box or EditableFields instead of Select in geofield ?

I want to have a editable Dropdown box, which users can input their custom values too!

For example have a list of cities :

Berlin
Hannover
Hamburg
etc ...

users can select the cities, but also the should be able to type postal code in dropdown too!
like what ebay classifieds already have!

Thanks a lot :)

johnhanley’s picture

This is an old thread, but still super useful. Thanks caktux and dave.erwin.

BTW, it's useful to add a default value attribute:

$element['distance']['#default_value'] = '25';

Also the zip code text field size can be tightened up:

$element['origin']['#size'] = '15';

fehin’s picture

I want to change the position (weight?) of the zipcode form to come before the distance operator. I tried the code below but it didin't work.

function my_customizations_proximity_element_process($element, &$form_state, $form) {

  $element['origin']['#weight'] = 100;

  return $element;
}
johnhanley’s picture

@fehin, make origin "heavier" with a negative number:

$element['origin']['#weight'] = -100;
fehin’s picture

I tried that. It doesn't make a difference.

johnhanley’s picture

I'm successfully using the aforementioned technique so there must be something else skewing the element weights.

fehin’s picture

FileSize
6.86 KB

I'm using it with views search. Could that be the problem?
It looks like this:

geofieldsearch

johnhanley’s picture

What's the $element array look like when you examine the weight attributes for each of your fields?

In my case I also have 3 exposed filter fields: origin, distance and a taxonomy. I adjusted the order in Views so the taxonomy is last and then swapped the order of distance and origin using hook_proximity_element_process(). Easy peasy lemon squeezy.

fehin’s picture

I modified the views exposed form template. I removed parts that I didn't need and I moved the views-operator class below views-widget class and that solved it.

<?php if (!empty($q)): ?>
  <?php
    // This ensures that, if clean URLs are off, the 'q' is added first so that
    // it shows up first in the URL.
    print $q;
  ?>
<?php endif; ?>
<div class="views-exposed-form">
  <div class="views-exposed-widgets clearfix">
    <?php foreach ($widgets as $id => $widget): ?>
      <div id="<?php print $widget->id; ?>-wrapper" class="views-exposed-widget views-widget-<?php print $id; ?>">
        <div class="views-widget">
          <?php print $widget->widget; ?>
        </div>
        <?php if (!empty($widget->operator)): ?>
          <div class="views-operator">
            <?php print $widget->operator; ?>
          </div>
        <?php endif; ?>		
      </div>
    <?php endforeach; ?>
    <div class="views-exposed-widget views-submit-button">
      <?php print $button; ?>
    </div>
  </div>
</div>