Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This is a follow up of : #534452: Exposed filters are always optional
That patch is not only hiding the 'optional' form element but doing all filters required in the query.
So, if I add a Node: Title as a exposed filter, and I leave it empty the view query will have:
SELECT .... WHERE node.title = ''
Comment | File | Size | Author |
---|---|---|---|
#26 | views-optional-string-filter_1054272-27.patch | 467 bytes | Grayside |
#25 | exposed_filter_view_example.txt | 11.59 KB | bcweaver |
#25 | views-contains-filter-bug-1054272-25.patch | 668 bytes | bcweaver |
#1 | 1054272-views-string-filter-optional.patch | 659 bytes | dagmar |
Comments
Comment #1
dagmarHere is the patch.
Comment #2
drclaw CreditAttribution: drclaw commentedThanks for this @dagmar!
Was the removal of optional text filters on purpose? Or is this a bug? merlinofchaos mentioned in the other post that "It's possible that the 'optional' checkbox should not appear on string filters." which worries me...
Comment #3
dagmarThe checkbox should not be visible because text filters cannot be required. (Like merlinofchaos explained here).
However, it is a bug. The patch committed includes a change in the 'accept_exposed_input' function that changes the logic of the function. And makes all string exposed filters required "even" if they doesn't have an input.
The patch reverts only the change in the function mentioned above.
Comment #4
drclaw CreditAttribution: drclaw commentedGotcha. Thanks!
Comment #5
servantleader CreditAttribution: servantleader commented+1
Ran in to this regression when trying out the newest dev code on a copy a deployed site and noticed that it broke all my exposed filters. Confirmed that this patch works.
Comment #6
stella CreditAttribution: stella commentedThe patch solved the problem for me as well.
Comment #7
johnvPatch works for me, too : I couldn't leave the text filter empty - now I can again.
Since I am number 4 already --> RTBC
Comment #8
eric.chenchao CreditAttribution: eric.chenchao commentedThis patch also works for me. Thank you :)
Comment #9
dawehnerThis bug has been around for too long.
Commited the patch to all three branches.
Comment #10
drclaw CreditAttribution: drclaw commentedThat's great! Thanks @dereine!
Comment #12
GRRaka CreditAttribution: GRRaka commentedCode matches the patch, but I am still having this problem in dev.
Comment #13
dawehnercan you tell us more about your configuration?
See http://drupal.org/node/571990 for informations how to help us to help you.
Comment #14
GRRaka CreditAttribution: GRRaka commentedI downloaded the lastest dev version on 4/12.
When filters are empty, they are being generated in the SQL command as = (''). This causes no results to be returned.
Here is the SQL from the dev version
WHERE (node.type in ('registration'))
AND (UPPER(node_data_field_reg_no.field_reg_no_value) = UPPER('03-160'))
AND (UPPER(node_data_field_reg_no.field_pi_last_value) = UPPER(''))
AND (UPPER(node_data_field_reg_no.field_cont_level_value) = UPPER(''))
AND ((node_data_field_reg_no.field_status_value) = (''))
AND ((node_data_field_reg_no.field_inst_abr_value) = (''))
ORDER BY node_data_field_reg_no_field_reg_no_value ASC
Here is the SQL from alpha3 version:
WHERE (node.type in ('registration'))
AND ((node_data_field_reg_no.field_reg_no_value) = ('03-160'))
ORDER BY node_data_field_reg_no_field_reg_no_value ASC
The patch mentioned in #1 is already in my code.
Comment #15
esmerel CreditAttribution: esmerel commentedComment #16
dawehnerWhat kind of field are this cck fields? Numeric, text ...
Comment #17
GRRaka CreditAttribution: GRRaka commentedThey are all text
Comment #18
dawehnerCan you give us a easy way to reproduce the issue? For example describe how to setup the cck field + provide an export of the view.
Comment #19
dafederThis occurs in D7 as well. For instance, set content title as an exposed filter in a content view, and nothing will show unless there is text in the field. This is especially problematic if you have several exposed filters on the same view.
Comment #20
dawehnerCan you please update to the latest version of views? There should be a fix in there.
Comment #21
dafederThat did it!
Comment #22
dawehnerNice!
Comment #24
bcweaver CreditAttribution: bcweaver commentedFWIW I am experiencing the exact problem described in this duplicate bug report: Error using Exposted Filter for Field with Operator "Contains Any Word" or "Contains All Words" and Pager
The patch provided here can't be applied to Views-7.x-3.1..
Comment #25
bcweaver CreditAttribution: bcweaver commentedI am still experiencing this problem with Core 7.12 and views-7.x-3.1. I've attached an exported view which demonstrates the bug--click the reset button in the preview and you will get an SQL error.
I've also found a way to fix the problem but I'm not familiar with views code and I think my patch isn't addressing the core issue. Patch attached.
The patch simply adds a check to the op_word() function in handlers/views_handler_filter_string.inc.. it checks if the operator is "word" or "allwords" and if a filter value has been provided.. if operator is 'word' or 'allwords' and no filter string is departed, it returns from the op_word() function without doing anything. This solves the problem, but I think the "correct" solution would be to prevent the op_word() function from being called in the first place if no filter string is provided.
Any advice would be much appreciated.. Thanks
Comment #26
Grayside CreditAttribution: Grayside commentedThe attached patch appeared to fix this problem for me. It also revealed the Optional option.
This patch was rolled against 6.x-2.x. I observed the same code in 6.x-3.x, but not in 7.x-3.x.
Not setting to Needs Review since this issue is now targeting 7.x, but this patch seems to need separate review from a 7.x solution.
Comment #27
mototribe CreditAttribution: mototribe commentedany update on this issue for 7.x? I'm trying to get the "contains any words" filter to work.
thanks