Hi,
I see there's no way to hide the default value of the distance exposed filter like version 5 can. For example, if the default distance is set to 5 miles, and in the distance exposed filter, it shows 5 miles and it's exposed; In version 5, 5 miles distance can be hidden when it's chosen as a default value.

Can this be done?

Thanks,

Comments

cyberwolf’s picture

I vote for this. We currently accomplished this with a hook_form_alter() but it would be better if the module has such an option (not exposing the distance) built-in.

function mymodule_form_alter(&$form, $form_state, $form_id) {
   if ($form['#id'] == 'views-exposed-form-some-view-identifier-page-1') {
       $form['distance']['search_distance']['#type'] = 'value';
       $form['distance']['search_distance']['#value'] = $form['distance']['search_distance']['#default_value'];

       $form['distance']['search_units']['#type'] = 'value';
       $form['distance']['search_units']['#value'] = 'km';
   }
}
tevih’s picture

+1 :)

tevih’s picture

Cyberwolf - did you create a custom module to accomplish this, or was this put into a template.php file? Either way, can you please outline the steps you took to get this to work?

Thanks!

cyberwolf’s picture

@tevih I created a custom module for this, in the example code above just replace "mymodule" with the desired module name, and replace 'views-exposed-form-some-view-identifier-page-1' with the right form ID. Please keep in mind, I consider this as a quick and dirty fix, it would be much better if it was an option in the views filter. I'll see if I can come up with a decent patch...

tevih’s picture

thanks! I'll give this a whirl until a better solution comes up

chrishks’s picture

+1 Thanks for this Cyberwolf - I just thought I would share a little amendment:

$form['distance']['search_distance']['#type'] = 'value';

I found that using the above meant that the search_distance value wasn't used in the URL. My GMap view didn't seem to mind, but my table view didn't return any results. However if you change that bit to:

$form['distance']['search_distance']['#type'] = 'hidden';

Then your default value (e.g. 50 miles or whatever) goes into the URL and the table view produces results again. Not anything special but slightly better than doing the equivalent in CSS.

legolasbo’s picture

Issue summary: View changes
Status: Active » Closed (outdated)

Closing old D6 issues as D6 is end of life