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 = ''
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dagmar’s picture

Status: Active » Needs review
FileSize
659 bytes

Here is the patch.

drclaw’s picture

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

dagmar’s picture

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

drclaw’s picture

Gotcha. Thanks!

servantleader’s picture

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

stella’s picture

The patch solved the problem for me as well.

johnv’s picture

Status: Needs review » Reviewed & tested by the community

Patch works for me, too : I couldn't leave the text filter empty - now I can again.
Since I am number 4 already --> RTBC

eric.chenchao’s picture

This patch also works for me. Thank you :)

dawehner’s picture

Status: Reviewed & tested by the community » Fixed

This bug has been around for too long.

Commited the patch to all three branches.

drclaw’s picture

That's great! Thanks @dereine!

Status: Fixed » Closed (fixed)

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

GRRaka’s picture

Status: Closed (fixed) » Needs review

Code matches the patch, but I am still having this problem in dev.

dawehner’s picture

Status: Needs review » Postponed (maintainer needs more info)

can you tell us more about your configuration?

See http://drupal.org/node/571990 for informations how to help us to help you.

GRRaka’s picture

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

esmerel’s picture

Status: Postponed (maintainer needs more info) » Active
dawehner’s picture

What kind of field are this cck fields? Numeric, text ...

GRRaka’s picture

They are all text

dawehner’s picture

Status: Active » Postponed (maintainer needs more info)

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

dafeder’s picture

Version: 6.x-3.x-dev » 7.x-3.x-dev

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

dawehner’s picture

Can you please update to the latest version of views? There should be a fix in there.

dafeder’s picture

That did it!

dawehner’s picture

Status: Postponed (maintainer needs more info) » Fixed

Nice!

Status: Fixed » Closed (fixed)

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

bcweaver’s picture

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

bcweaver’s picture

Status: Closed (fixed) » Needs work
FileSize
668 bytes
11.59 KB

I 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

Grayside’s picture

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

mototribe’s picture

any update on this issue for 7.x? I'm trying to get the "contains any words" filter to work.
thanks