Views 2 Exposed Filter Default Value Changes with (Url) Argument
mdblue - January 19, 2009 - 00:04
| Project: | Views |
| Version: | 6.x-2.2 |
| Component: | taxonomy data |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | won't fix |
Jump to:
Description
- Created a view block with "search terms" exposed field and "taxonomy term" exposed field.
The Default value for "taxonomy term" is "Any".
View works perfectly and filters based on taxonomy term and/or search Term.
Question: Is it possible to create "Argument" to pass the url to "Default Value" for Taxonomy Term Exposed filter ?
For example, when a url is visited with taxonomy term "A", the Default Value of the Exposed Filter will be "A" instead of "Any" so that users can search within "A" immediately, instead choosing "A" one more time.
This is a common use case and it will be great if there is a way to proceed.
Thanks

#1
Sorry, you cannot currently accomplish this with Views.
#2
I would also like this to be possible. Views is keeping arguments and using them, and passing them to filters would be better.
#3
+1
#4
+1
#5
This can be accomplished like so. Hardly elegant but it does seem to cut the mustard.
The contents of a CCK select list are used rather than a taxonomy term but the problem is much the same.
View configuration
View accepts a single argument derived from a CCK field select list widget.
Filter is exposed as a block.
Filter block also includes the same CCK field as referenced in the argument.
Issue is that when filtering the view using the argument the block filter selection does not match the argument.
In the snippet below 'field_make_value_many_to_one' is the name of the form select item that you want to match to your argument.
<?php
function mymodule_form_alter(&$form, $form_state, $form_id)
{
// function seems to get called twice so need to cache
static $term;
switch($form_id) {
// issue:
// when filter view using argument the exposed filter block selection does not
// match the argument
//
// we want to modify the form select element selection state
case 'views_exposed_form':
// take a peek
// dvm($form_state['view'], 'hook_form_alter');
// get the view argument if defined
$term_arg = $form_state['view']->args[0];
if (isset($term_arg)) {
$term = $term_arg;
}
// change our input as required
if (isset($term)) {
$form_state['input']['field_make_value_many_to_one'] = $term;
}
break;
}
}
?>
#6
nice - where i have to put this snippet?
#7
You will have to put it into a module, hence the mymodule_ prefix.
Read up a bit on Drupal module hooks if you are in doubt about this.
In essence hook_form_alter simply doles out form definitions to any modules that are interested.
#8
thanks a lot
momper
#9
+
#10
subscribe
#11
subscribing. this looks good. thanks for the tip.
Chris
#12
Do you mean that's it's logically impossible? or that there is no current mechanism?
It sounds like a useful feature to me.
#13
I'm also interested in having a default value different from 'any'.