Hi,

I've set up a view exposed filter, doing the following steps :
- Create a CCK Integer field (Computed CCK Field), let's name it Doors.
- Create a view
- Create an exposed filter on this field, with the operator Between

I would like to know if there is a way to do the following :
I want to filter results where Doors is in a defined range.
The maximum extent of this range is very finite, let's say it can range from 0 to 20.
However, Views always uses 2 regular Textboxes when using exposed filters (with the Between operator).
So, is there some way to use a Select List, and still be able to use the number operators ?

Thanks for your attention,
Ask me if it isn't clear enough.

Comments

dawehner’s picture

It is clear for me.

I think the cleanest way to do it, is to override the filter handler of the computed field, to support between. Sure that needs custom coding.

As alternative you could use hook_form_alter and alter the exposed form.
Then you could use hook_views_pre_query to alter the $view, and change the filters as you want.

artscoop’s picture

Hi,

Thank you for your answer.
As it looks more robust to use the form_alter hook, I'm going to read the documentation about it.

(I'm not a Drupal developer but) Is it ok to add this hook in my template.php ?

dawehner’s picture

No.

You can only write your hook implementation in a module.

merlinofchaos’s picture

Project: Views (for Drupal 7) » Content Construction Kit (CCK)
Component: exposed filters » Views Integration

This would have to be provided by CCK, I think. Though I suppose it's possible that a generic patch to Views' numeric filtering could do it too. I'm a little torn. Maybe Markus should just send this back to Views, but I'll let him decide.

markus_petrux’s picture

It seems to me this needs custom coding. Something like this, to be implemented in Views/CCK would have to include a method to define the ranges you wish for each option in the select list, and a simple Number field (or a Computed field) can only store one value.

I would follow dereine's advice in #1 here.

markus_petrux’s picture

Status: Active » Postponed (maintainer needs more info)

Switch issue status so I know I already visited this issue.

Bilmar’s picture

hello, I came across the same need and it was very easily solved with a custom module (the code I use is below)

// $Id$

function price_range_dropdown_perm() {
  return array('access price_range_dropdown content');
}

/**
* Alter the form to display dropdowns for price range
*/
function yourmodulename_form_alter(&$form, $form_state, $form_id) {
  switch ($form_id) {
    case 'views_exposed_form' :
      $price_from_options = array(
        '' => t('No Min'),
        '1000' => t('1000'),
        '1500' => t('1500'),
        '2000' => t('2000'),
        '2500' => t('2500'),
        '3000' => t('3000'),
        '3500' => t('3500'),
      );
      $price_to_options = array(
        '' => t('No Max'),
        '1500' => t('1500'),
        '2000' => t('2000'),
        '2500' => t('2500'),
        '3000' => t('3000'),
        '3500' => t('3500'),
        '4000' => t('4000'),
      );
      $field_price_value_from = array (
        '#type' => 'select',
        '#multiple' => false,
        '#required' => false,
        '#options' => $price_from_options,
        '#default_value' => 'No Min',
      );      
      $field_price_value_to = array (
        '#type' => 'select',
        '#multiple' => false,
        '#required' => false,
        '#options' => $price_to_options,
        '#default_value' => 'No Max',
      );
      $form['field_price_value']['min'] = $field_price_value_from;
      $form['field_price_value']['max'] = $field_price_value_to;
      break;
  }
}