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!

CommentFileSizeAuthor
#5 views_filter_summary-279191-3.patch1.52 KBAnonymous (not verified)
#4 views_filter_summary-279191-2.patch2.14 KBAnonymous (not verified)
#1 views_filter_summary-279191-1.patch584 bytesyched

Comments

yched’s picture

Project: Content Construction Kit (CCK) » Views (for Drupal 7)
Version: 6.x-2.0-rc3 » 6.x-2.x-dev
Component: Views Integration » Code
Status: Active » Needs review
StatusFileSize
new584 bytes

Looks 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.

ZMan9854’s picture

It 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!

merlinofchaos’s picture

Status: Needs review » Fixed

It'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.

Anonymous’s picture

Status: Fixed » Needs review
StatusFileSize
new2.14 KB

This 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.

Anonymous’s picture

StatusFileSize
new1.52 KB

whoops - cleaner patch

gcassie’s picture

Is there a similar patch that is available and/or needed for the Drupal 5 version of Views?

merlinofchaos’s picture

Does this actually work? It's not clear to me it will.

Anonymous’s picture

Do 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!

merlinofchaos’s picture

Status: Needs review » Fixed

ah HAH. I found an alternate solution to this.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.