Views filters do not respect default settings and upper bound doesn't work

voipfc - March 2, 2008 - 22:45
Project:Views
Version:5.x-1.6
Component:User interface
Category:bug report
Priority:normal
Assigned:Unassigned
Status:duplicate
Description

I have a filter with two number fields to set the range for a price value using "Greater than or equal" to and "less than or equal".

When the form is displayed the second one reverts to "Greater than or equal to".

I even modified the form code using the code below, at the if ($label == 'Max Price'), and still the less than or equal to value does not show up right.

Is there a bug in the form rendering code that ignores the value for the select option?

Furthermore it does not compute the "less than or equal" value properly when I run the code. Is this a known bug?

When the value of the number field is blank, the query fails when logically it should ignore that value.

Can anyone point me to the place in the views code where the query is generated, or at least the values entered are parsed?

<?php
function newsflash_views_filters($form) {
   
$view = $form['view']['#value'];
   
$o = '<div class="nf-vws-flr">';
   
$o_pricegroup = '<div class="nf-vws-flr-obj"><div class="pricegroup"><h3>Price Range</h3>';
    foreach (
$view->exposed_filter as $count => $expose) {
       
$label = $expose['label'];
       
$outlabel = '<h3>'.$expose['label'].'</h3>';       
       
$divlabel = str_replace(' ', '-', strtolower($label));
        if ((
$form["filter$count"]["#type"] == 'select')){ // && ($form["filter$count"]["#theme"] == 'taxonomy_term_select')
           
$form["filter$count"]["#size"] = 4;
        }
        if (
$label == 'Min Price') {
           
$form["op$count"]["#default_value"] = '>=';
        }
        if (
$label == 'Max Price') {
           
$form["op$count"]["#default_value"] = '<='; //code to change select value to <=
       
}
       
$formelement = drupal_render($form["op$count"]) . drupal_render($form["filter$count"]);
        if ((
$label == 'Min Price') or ($label == 'Max Price')){
           
$o_pricegroup .= '<div class="'.$divlabel.'"><div class="form-element-'.$count.'">'.$outlabel.$formelement.'</div>'.'</div>';
        } else {
           
$o .= '<div class="nf-vws-flr-obj"><div class="'.$divlabel.'"><div class="form-element-'.$count.'">'.$outlabel.$formelement.'</div>'.'</div>'.'</div>';
        }
    }
   
$o_pricegroup .= '</div>'.'</div>';
   
$o .= $o_pricegroup;
   
$o .= '<p>'.'<div class="nf-vws-flr-submit">'.drupal_render($form['submit']).'</div>' ;
   
$o .= '</div>';
    return
$o .drupal_render($form);
   
//return $o .'<div class="nf-vws-flr-obj">'.drupal_render($form).'</div>'.'</div>';
}
?>

#1

voipfc - March 4, 2008 - 21:45

I have confirmed this as a definite bug. The views filters uses the settings of the first filter and applies them to the second one. In effect it treats all the number filters as identical.

#2

merlinofchaos - March 16, 2008 - 17:38

This is a known bug in Views; you cannot have the same filter exposed twice. The IDs get confused and it can't tell them apart.

#3

alb - April 16, 2008 - 22:54

think isn't a bug but only an options;
in table also if there are two filter, when in php code you set 2nd filter, really
the query cannot know that 2nd set is only for 2nd value in db;
(this if I remember structure of table and query insertion )

think also for expert is simple to solve;
but in next views version will be insert?

#4

sun - September 20, 2008 - 23:38
Status:active» duplicate

Marking as duplicate of #250769: Adding same filter twice doesn't work

 
 

Drupal is a registered trademark of Dries Buytaert.