Closed (fixed)
Project:
Views (for Drupal 7)
Version:
7.x-3.x-dev
Component:
exposed filters
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
31 May 2009 at 16:04 UTC
Updated:
13 Jul 2019 at 04:16 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
dawehnerBut the Views Integration of CCK ist not part of Views
Comment #2
junedkazi commentedI have also noticed this problem.
When the field is not exposed as a filter and the field operator
is set to IS EMPTY/ IS NOT EMPTY it works perfectly fine
but when we expose the same filter and search based on
IS EMPTY/ IS NOT EMPTY operator there is no change in results.
I am using Drupal 6.12
cck - 6.x-2.3
views - 6.x-2.6
Any help is appreciated.
Thanks
Juned Kazi
Comment #3
j0k3z commented+1
Comment #4
junedkazi commentedJust changing it to critical to bring it to notice.
Comment #5
junedkazi commentedcan anyone of the maintainers pls look into this issue.
If u need anymore info pls let me know I will try and
provide as much info as I can to get this problem
solved.
Comment #6
Flying Drupalist commentedComment #7
michellekim commentedsubscribed
Comment #8
markus_petrux commentedI've been unable to reproduce this issue. Please, try with latest development version of CCK to see if that makes a difference.
If the problem persists, then please provide steps to reproduce. First try with a simple view using text or number fields provided by CCK itself. If that works, then try with noderef. If that works, then try with any other field.
If the problem is related to a field that is not provided by CCK itself, then this issue needs to be transferred to the proper queue.
Please, describe how the field you wanted to filter by is defined, the field type, if it accepts multiple values, the SQL statement generated when using the EMPTY/NOT EMPTY operator -vs- any other operator, etc.
Comment #9
markus_petrux commentedActually, I think this was really fixed in Views itself. See #323049: Add 'allow empty' support to views_handler_filter_in_operator
Comment #11
aren cambre commentedThis is not fixed. I can reproduce, and I have the latest 6.x releases of core, CCK, and Views, and Views 6.x-2.6's release notes show that #323049: Add 'allow empty' support to views_handler_filter_in_operator was included.
I tested the Is empty (NULL)and Is not empty (NULL) filters on a Text field type. When, non-exposed, the filters work as expected. When exposed, they stop working.
Note that all I did was expose the filter. I did not select any other options. This just shows the filter description and an Apply button on the view.
Comment #12
markus_petrux commentedThis feature in CCK is inherited from Views handlers, so the correct layer where needs to be fixed is Views (see views_handler_filter_string, views_handler_filter_numeric, views_handler_filter_in_operator, ...). Transferring to he proper issues queue.
Comment #13
aren cambre commentedI just realized this duplicates #573298: Cannot set exposed binary filters without "Unlock operator". The problem is that the Views UI does not show an operator to turn on/off empty/not empty filters.
Comment #14
giorgio79 commentedI am not sure if this is only a UI issue. Setting it back to active. It is one thing the UI does not make sense, but the query simply does not work, if I try to filter for fields that are "EMPTY" fields...Even text fields.
Also, as I understand EMPTY is meant to represent the SQL term, because in that case instead of
Is empty (NULL)and Is not empty (NULL)
it should be
Is empty (NULL)and Is not empty (NOT NULL)
Is NOT EMPTY works fine for me.
Comment #15
erkan_o commentedI have the same problem here, nothing fancy, just an exposed filter on a TEXT field. When I search for "Is null", nothing happens. But it works if the CCK field is not a TEXT field.
BUT, if I do a search and selects "Begins with..", type a letter and get a result, from then on if I select "Is null" then I get result. But that is simply not possible to release to clients.
Anyone got a quickfix?
Comment #16
heylookalive commentedAs a quick fix, I just added the same field again in addition with 'is not equal to' then the value blank, just not exposed.
Btw:
Drupal 6.14
CCK 6.x-2.6
Views 6.x-2.7
Comment #17
erkan_o commentedSo lets find out if I understand you right.
-You have one field with an exposed filter, it does not work when you search for "Is null, empty"
-So you add the field again, so you have two fields of the same fieldname, one exposed and one not exposed, the one not exposed you assigned it to "is not equal to" and left value empty?
-And the above scenario is fully working?
Am I correct?
I just tried the above and confirm not working.
Views 6.x-2.8
CCK 6.x-2.6
Drupal 6.15
I invested 5 weeks into this application where it is vital for the client to be able to search data and filter results on empty data in order to know on what result data needs to be filled in. I should off course have tested that it should be possible to search for empty fields with an exposed filter at the first time but I asumed it should have been working.
So does anyone know if searching data with exposed filters works in Drupal 5 or 4, I need to have this app working on tuesday or the clients will bust my ass. Please heeeeeelp!
----
Slight update.
Ok, I got it "somewhat" working. This is how I did it.
If I want to search all customers who have not registered a webadress:
-I go to the exposed filter field "Webadress",
-Then I chose the first option in the drop down ("is the same as"), then I put one space (empty character) in the text field.
-Then without clicking the search button I chose option "Is empty" and click on the search button and then it works!
So now I need to find out how to put an empty character in the text field when I have chosen to search for empty data in fields.
Comment #18
erkan_o commentedHi,
Just wanted to let people know how I solved it for future reference.
I created a custom module with hook_form_alter(), then I added "onChange=searchFix("field-somethingxyz-value-op") to every form field that I needed to search on. With drupal_add_js() I could add the relevant JS to put an empty space in the field so that I could search on fields that where empty in an exposed filter.
Ok, below follows my incredible lame code, laugh all you will but it saved my ass from being busted tomorrow :-)
Have fun!
Comment #19
smzur22 commentedsubscribing..
Comment #20
demeritcowboy commentedThe problem seems to be that views is expecting an xxx_value parameter in the query string even when the xxx_op=empty, and does nothing if it's not there.
So the first time through if you select Is Empty, it doesn't set an xxx_value in the query string, but then if you select Is One Of and then submit and then choose Is Empty, it "remembers" the xxx_value parameter and includes it in the query string and so it works.
So either it needs to somehow set something for the xxx_value right when the form is first displayed, or better, it needs to understand that if the xxx_op=empty then it doesn't need the xxx_value.
Does anybody know where in the code it's doing this?
Comment #21
aren cambre commentedComment #22
demeritcowboy commentedSee attached patch for handlers/views_handler_filter.inc.
Comment #23
Encarte commentedsubscribing
Comment #24
fatstar415 commentedPatch for this issue
Please note that this patch is not made relative to the module's root directory.
Please apply patch under the folder handlers/ in your views root directory.
Comment #25
fatstar415 commentedComment #26
giorgio79 commentedComment #27
dawehnerwe don't do this.
A better codestyle would be cool.
huh?
Powered by Dreditor.
Comment #28
fatstar415 commentedSomething that I do in a company. Forgot to take that out.
Comment #29
Encarte commentedComment #30
Flying Drupalist commentedYou gotta follow the drupal coding standards.
http://drupal.org/coding-standards
Comment #31
dawehnerso needs work.
A inline commit perhaps would be cool, why we do this here.
Comment #32
Mike Dodd commentedI have just cleaned this patch up a bit.
Comment #33
dawehnerCould we use spaces and ''){ should be '') {
a inline comment would be cool!
Powered by Dreditor.
Comment #34
homoludens commentedsubscribe
Comment #35
rburgundy commentedsubscribe
Comment #36
dagmarRellolled against DRUPAL--3 branch. Fixed coding standards.
Comment #37
bojanz commentedNice work. Let's get this to Earl.
Comment #38
merlinofchaos commentedCommitted to all branches.
Comment #40
Encarte commentedI still get this same problem in Views 6.x-2.12 (Chaos tool suite 6.x-1.8 and CCK 6.x-2.9)
Comment #41
giorgio79 commentedI only get it with Text types, with Integer fields it works fine now.
Comment #42
Encarte commentedI get it even with taxonomy term id filter (even not exposed)...
Comment #43
dawehnerPlease try out the views 2.x dev version. As earl said he commited it already.
Comment #44
Encarte commentedSorry, but, since he commited in 2010-Nov-18 and 6.x-2.12 was released in 2010-Dec-15, I thought that 6.x-2.12 would have the fix. I'll try out the dev, then. Thanks.
Update: But... there's no views 2.x dev version in the project page. Where do I get it?
Comment #45
giorgio79 commentedNeed to try the 6.3 version
As Earl said in #38:
Comment #46
dawehnerand the link because you didn't searched on google: http://drupal.org/node/95897
Comment #47
bojanz commented2.12 was just a security release, that's why it doesn't include the fix.
2.x dev (or 3.x dev) is what you need.
Comment #48
Encarte commentedSeems to be fixed in last dev. Thank you.
Comment #50
giorgio79 commentedYes works great! Much appreciated.
Comment #51
Encarte commentedThis problem is active once more in the July 9, 2011 - 01:47 Views 6.x-2.x-dev.
Comment #52
Encarte commentedTried the September 1 dev and it seems to be fixed. Thank you Dereine.
Comment #54
chronosinteractive commentedI believe this issue still exists in Views 7.x-3.0-rc1. Creating a filter for NULL/NOT-NULL works fine, until it is exposed in which it then no longer works.
Comment #55
clemens.tolboomI'm querying the system table on status == 'All' but when in file views_handler_filter_boolean_operator.inc with $value == 'All'
the code falls down to the last add_where ... it should not add any where.
Comment #56
trudog commentedthat's correct! exposed filter doesn't work for null/ not null. i get the following error:
field_cl_nid is a cck node reference type.
Comment #57
jamix commentedI'm also experiencing this issue in Views 7.x-3.1. When exposing an "Is empty" filter for a node reference field, I get the same error as pisicosu in #56. When exposing an "Is empty" filter for a text field, I get a text field in the filter instead of an (expected) Empty/Not empty select box. Hopefully this will get fixed soon.
Comment #58
jvieille commentedStill there in 6x-2.16 from 12/12//2011
Comment #59
deciphered commentedWhile I agree that the widget being used for the EMPTY/NOT EMPTY operator shouldn't be a textfield, that's probably better left to Better Exposed Filters.
As for the issue itself, only having skimmed the content of this issue but having delved into the code it is evident that there is an issue with the code itself (at least in D7):
The main issue is that from my testing
$valuewill always be an array() with a key ofvalue, so this code does nothing. My proposed and tested fix is attached as a patch, and it will return TRUE or FALSE toggling the exposed filter on and off if the value provided is empty or not empty.Comment #60
deciphered commentedPatch round 2, this time I've chosen to change the form element to a Select field with the values ALL, Yes and No, and depending on the choice the operator will either be ignored (Show all), used as is (Yes) or toggled to the opposing operator (No).
Comment #61
dawehnerThese kind of code should be part of views_handler_filter_boolean_operator then. To be able to extend functionality is the great advantage of OOP.
Comment #62
qasimzee commentedany update on this?
Comment #63
dchatrySubscribing
Comment #64
ahmad.khalid commentedhi i used your patch in all version of drupal 7 but using that patches is empty/not empty filter doesn't work when exposed please help me.how that work
thanks
Comment #65
ahmad.khalid commentedthank you very much of all for help me to resolve that problem.if anyone want to help me then contact me
Comment #66
mikeker commented@dawehner said in #61:
True, but we would have to add another filter type, such as "Content: empty/not empty" because the "Content: " is an instance of
views_handler_filter_stringnotviews_handler_filter_boolean_operator. Or the boolean-specific stuff would have to be moved fromviews_handler_filter_boolean_operatortoviews_handler_filterwhich kinda ruins the encapsulation.Or am I misunderstanding the Views class hierarchy?
Comment #67
klucid commentedThe patch in #60 works great. Thank you! I'm surprised it hasn't been committed as of 7.x-3.7.
I may have to open another issue, but is there a reason I cannot use Better Exposed Filters (http://drupal.org/project/better_exposed_filters) to change the drop down menu to a radio button?
Comment #68
mikeker commentedBumping to needs review in hopes of getting some feedback on #66...
Comment #69
Shevchuk commentedConfirm patch in #60 works perfectly. As it solves the problem, I think it might be a good idea to commit it, and then refactor (see #61), so everyone gets happy =)
P.S. Thanks, Deciphered =)
Comment #70
Shevchuk commentedOne tiny issue, though: empty value and 'All' value are not handled properly because of
$value = $value['value']— this means$value(being a string, not array) becomes'A'instead of'All'. So,if ($value == 'All' [...] return FALSE;never fires.Quick fix is to add
is_array()check so that$valuedoesn't get wrongly overwritten. Fixed patch attached.Comment #71
Sinan Erdem commentedAfter applying the patch to 7.x-3.7 version, I am receiving some warnings like that:
Strict warning: Non-static method views_handler_filter_boolean_operator::value_form() should not be called statically, assuming $this from incompatible context in views_handler_filter->exposed_form() (line 777 of /mysite/sites/all/modules/views/handlers/views_handler_filter.inc).
For each "not empty" exposed filter, it prints one of those warnings.
Comment #72
clemens.tolboomWhy is this static call used? This was introduced in #60.
Comment #73
clemens.tolboomThe use of the static call needs some documentation I guess or converted to a non static call.
Comment #74
Thithi32 commentedI'm having the Strict Warning issue but I don't know how to solve it.
Anyone has a correction available?
Comment #75
bruceci commented#60 patch to views7.37 do not work ,operator dispear as before。
Comment #76
amir simantov commentedNeither #70 work for 3.37
Comment #77
seanrI just got bitten by this as well (Strict warning: Non-static method views_handler_filter_boolean_operator::value_form() should not be called statically, assuming $this from incompatible context in views_handler_filter->exposed_form() (line 777 of /.../views_handler_filter.inc).). Does anyone have any suggestions for fixing this?
Comment #78
altcom_alan commentedI've rerolled patch in #70 against 7.x-3.7 and also changed the static call to creating a new views_handler_filter_boolean_operator() object, setting the values for it as well as $this and then calling value_form() on the object like so:
I've tested it works for me and I've even used hook_form_alter to change the select list into a check box so I have a view that exposes IS NULL or IS NOT NULL filters as a simple on / off checkbox (rather than an on / off / opposite choice provided by the select list)
Comment #79
josebc commentedThank you
patch applied and working correctly, hover it doesn't apply if views in another location than sites/all/modules/views
can you just re-generate that patch so it works for all locations .
Comment #80
jfrederick commentedRe-rolled #78 against 7.x-dev, patch also applies cleanly to 7.x-3.8, and incorporates suggestion from #79.
Comment #81
W.M. commentedPatch at #80 works perfectly and solves the issue. I think it should be committed in next stable release.
Comment #82
1mundus commentedI have this problem with Views 3.10 and Drupal 7.31. Before the last upgrade (3.8 to 3.10) if I selected "Is empty (NULL)" as exposed filter, that field would disappear from filter list, but it worked well.
Now it doesn't disappear anymore (and that's great), but it doesn't work either. If I use the same filter from Views UI and avoid using it as exposed filter, it works properly.
This behavior occurs only with taxonomy fields. Text fields work well, but their filter still disappears when "is empty" filter is applied.
Comment #83
mbnsorg commentedUsing Views 3.10 and Core 7.35, when using Exposed Filter, when either Is empty (NULL) or Is not empty (NOT NULL) are selected, the filter itself completely disappears. Hitting Apply at that point (for no intuitive reason) results in an incorrect query (the query uses a different and unrelated field).
I tried the above patch in #80, adjusted for 3.10, and the issues remain.
Has anyone resolved issues with Is empty/not empty? This seems so obvious, I am not sure what I am missing.
I looked through Views code and see references to $this->definition["allow empty"], which seems related to this somehow, but I do not have bandwidth at the moment to fix Views code.
If there is no fix to this, is there a hook I could use to just remove those options entirely from the Exposed Filter operators?
Thanks for any help.
Edit: This seems more related https://www.drupal.org/node/1249684
Comment #84
ciss commented@mbnsorg: https://www.drupal.org/node/1087348#comment-9834587 might be related to your issue.
Comment #85
jbrandl07 commentedI recently ran into this issue as well when trying to expose a filter to show nodes with body fields that are empty or not empty. I added a grouped filter with a select widget type. I then added to options to the select. One I called "Body Field is Empty" with an operator of "Length is shorter than" and a value of "1". The other was called "Body Field is Not Empty" with an operator of "Length is longer than" and a value of "1". This suited my needs for what I was trying to accomplish and got around this null/not null issue. I hope this helps.
Cheers,
Comment #86
sagacity commented#85 really helped, thanks @jbrandl07
Comment #87
sbilde commented#85 Help me as well, along with this patch: https://www.drupal.org/files/issues/views-1818176-12.patch .. Thanks.
Comment #88
djcj commentedMy exposed date filter would not work for NULL or NOT NULL. (Drupal 7)
My work-around was to comment out the following lines from this file:
/modules/views/handlers/views_handler_filter_date.inc (around line 135)
Now it works correctly.
Comment #89
portulacaI was able to work around this for Content: File field by using Grouped filters option. I'm copying my answer from http://drupal.stackexchange.com/questions/64730/exposed-filter-for-file-...
I added Content File:fid filter and exposed it.
Then I selected Grouped filters option (instead of the Single filter).
In the table that appears where you can set your options, the first one is Any (default), in the second one I added
Label YES
Operator Is greater than
Value 0
and I removed the third table row as I didn't need it.
This filter works! It shows the filter with 2 options: Any and YES. Any is default and shows all results. If I select YES it only shows results that have a file attached :)
I also added Content: file among Fields so it's easy to test the filter.
Comment #90
proweb.ua commentedPatch at #80 works
Comment #91
duneblI have tried to group all the patches/issues about this problem into one issue: https://www.drupal.org/node/2704699
Comment #92
saurabh.dhariwal commentedLatest patch is working fine! Thanks for contribution Guys!!
Comment #94
djpable commentedI'm not able to apply this patch to the current version 7.x-3.15.
It seems already applied but after update my NOT NULL filters are broken again.
Comment #95
damienmckennaReroll.
Comment #96
kiwibytes commentedI have the same problem in Views 7.x-3.16. I have applied an exposed filter in a view that is set to IS NOT EMPTY for an image field in profiles. The filter is visible as a checkbox but the value is applied regardless of state of checkbox and results are shown for profiles whose image field is not empty.
Is there a released version of views that has this patch? I'm asking as I don't know how to apply the patch.
Comment #97
dzy commentedReroll for 7.x-3.20 copy from #95.
Comment #98
stred commentedconfirm that #97 is working
Comment #99
damienmckennaThe patch needs to be updated to use long array syntax so we don't break PHP 5.3 again :)
Comment #100
damienmckennaFixed array syntax.
Comment #101
damienmckennaComment #103
damienmckenna@kiwibytes: Just so you understand it, when there's an open issue, i.e. one with a status that doesn't say "fixed" or "closed", that means the change has not been committed.
Committed.
Comment #105
troybthompson commentedI just found this thread and it isn't helping in my situation. I have a List (text) field and when I select Null in the exposed filter, it doesn't work and nothing shows up in the query string to show it's being taken into account. BUT, if I first do a search for something in particular in the list first, then change it back to Null, it does get taken into account and works fine.
When you select "Is Empty NULL" the form-item-field-***-value select gets hidden. If Any / All is selected before it gets hidden, the whole thing including the null is ignored. If it's set to one of the options before it's hidden, that value triggers the null to be taken into account and it works. The value itself is ignored in the query (as it should).
So through testing multiple times it may have worked, but starting with a clean slate (in my case at least) it doesn't. Hope this helps.
Comment #106
Azor Ahai commentedCan confirm, the patch committed doesn't resolve the issue.
Comment #107
guypaddock commentedPlease see if #3067681: Exposed Filters that Expose the "is empty" and "is not empty" Operators are Not Handled Properly initially, which I've just filed, captures the issues you guys are seeing.