Hi,
I have a content type with a select list with a few options, such as
0|Active
1|Complete
2|Unsold
When trying to filter a view by the 0 (Active) option, the filter does not save the value. It does save when selecting a non-zero option (i.e. 1|Complete). When saving the filter with the zero option, I see it shows this (for example) in the filters box, which I suppose should read "Listing status = 0 or...":
Content: Listing status or
Node: Type = Auction
I've tested this with various data types for my CCK field (text, integer, etc), and all do the same thing. I've also made new fields with other content types and have found the same issue.
Thanks very much!
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | views_filter_summary-279191-3.patch | 1.52 KB | Anonymous (not verified) |
| #4 | views_filter_summary-279191-2.patch | 2.14 KB | Anonymous (not verified) |
| #1 | views_filter_summary-279191-1.patch | 584 bytes | yched |
Comments
Comment #1
yched commentedLooks like a views bug.
This is caused by views_handler_filter_in_operator::value_submit(), that uses array_filter() on the list of selected values, thus filtering out the '0' value.
Additionally, when removing that array_filter (which I'm in no way assuming is the right fix), there is a display error in
views_handler_filter_in_operator::admin_summary() :
When selecting values 0, 1 and 2, the admin summary reads 'field = 01, 2' instead of 'field = 0, 1, 2'.
Attached patch fixes only that display bug. Leaving it to merlinofchaos on the array_filter issue.
Comment #2
ZMan9854 commentedIt looks like the actual view itself is affected by this bug as well - when sorting by 'Active' with the exposes filter (value = 0), I get all nodes regardless of the type (both ajax and static).
Thanks for such a quick patch - can't wait to start using it!
Comment #3
merlinofchaos commentedIt's not the array_filter that's really the problem here. If you use checkboxes with an array key of 0, then FAPI cannot tell if that checkbox is checked, as the 'unchecked' is set to (integer) 0, whereas a checked item is set to the key value.
This means that, if you use 'checkboxes' with one of the options as 0 => 'some string', it always appears to be unchecked. Removing that array filter simply doesn't filter out unchecked items.
More and more I'm wanting to implement my own #views_checkboxes that works more like 'select' with multiple => true. There's a lot of code in Views to deal with checkboxes having a bunch of strange issues.
The display patch is committed.
Comment #4
Anonymous (not verified) commentedThis patch should fix the query for both CCK and non-CCK fields that use or extend views_handler_filter_in_operator. If you select an option with a key of zero it will now get added to the query.
Comment #5
Anonymous (not verified) commentedwhoops - cleaner patch
Comment #6
gcassie commentedIs there a similar patch that is available and/or needed for the Drupal 5 version of Views?
Comment #7
merlinofchaos commentedDoes this actually work? It's not clear to me it will.
Comment #8
Anonymous (not verified) commentedDo you mean whether is_numeric(0) == TRUE? It is in PHP5+ (and there's a test to prove it), but I can't test or be sure about how PHP4.x behaves. Maybe someone with PHP4 could test?
If you just mean does it work in Drupal, then all I can say is that it does for me!
Comment #9
merlinofchaos commentedah HAH. I found an alternate solution to this.
Comment #10
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.