Hello, I'd really appreciate if someone can help me with this issue.
I have a profile for users, in this profile I have field "Date of birth" in which the users can enter the date (it is field of type Date).
I also have a computed field called Age, in which I calculate the value using the information entered in the date of birth field.
Finally I have a view in which a user can search persons, so, in that view I need a new field in which the users can search by range, something like this:
Age ranged: (then in a dropdown list)
x- 15-20
x- 20-30
x- 30-35
etc..
I would like to know if there is an easy (I really don't care if it's easy... :)) way to add this functionality to the view.
Obviously thanks a lot for all the tips that you can give me.
Claudio.
-** www.fileando.com **-

Comments
new filter
i'm not sure, but i think this should be a new filter for BETWEEN (i.e. a range). i don't think Views has this already
Issue
See http://drupal.org/node/84592 for an issue and workaround. Also, http://drupal.org/project/daterange might be worth a look for possible approaches, but I agree that a new Views operator 'Is between' is needed. It'd be nice to keep this in the same list as the views_handler_operator_gtlt() operators, but we'd need some code to add a 2nd filter textfield. Or, to make it simple we could just keep one form field and have some delimiter to get the lower/upper bound values. Needs some more thought.
Did you find a fix?
I am trying to the the same type of thing.
I have a computed field that the width of an image and returns "horizontal", "vertical", or "square".
I want to have an exposed filter that allows users to limit images to these parameters. (ie. if they select "vertical" they will only see vertical images.) The issue is that the computed field filter in views is only "Is Greater Than...." and i need something like the text filters.
Any suggestions?
I use a simple HTML form to
I use a simple HTML form to pass arguments to my view. On this form I have a select box with age ranges: 15-25, 25-35 etc... The action property of this form is an URL of the page where my view is placed (the form and the view can be on the same page). I use post method for passing values.
On my view edit page (something like /admin/build/views/allpeople_view/edit) there is collapsing fieldset called 'Arguments', and inside this setfield there is a text area called 'Argument Handling Code'. Here I use a PHP coding to do almost whatever I want with this view. I use $age_range = $_POST['user_age_range'] to get an age range, then I use explode() function to get $from and $to range values. And here is an important part that dinamically creates a filter for my view:
$pos = count($view->filter); // gets current filter index
if ($age_range ) {
$view->filter[] = array(
'vid' => $view->vid,
'tablename' => '',
'field' => 'node_data_field_user_age.field_user_age_value_default',
'value' => $from,
'operator' => '>=',
'options' => '',
'position' => $pos++,
'id' => 'node_data_field_user_age.field_user_age_value_default',
);
}
// IMPORTANT: Invalidate the cached query for this view, as it'll need to be regenerated on each request
$view->is_cacheable = 0;
that's it. Note, my computed age field is called user_age and is reached here as 'node_data_field_user_age.field_user_age_value_default'. I simply generate 2 new filters for my view, the first one makes sure tat displayed people are not younger than received $from value and second filter makes sure tat displayed people are not older than received $to value. Filters are ANDed by Drupal, so I get what I need.
I hope this was helpfull
Good luck
Andriy