I have two content types, "condo", and "house". In "condo" I have a field "condo_bedrooms", and in "house" I have the field "house_bedrooms". I display both fields in the view and filter both fields using check boxes from BEF. The fields are integer. I also filter for content type.

If I select only the house content type, and select "1" for house_bedrooms, the view works. But if I leave the checkbox for "1" in house_bedrooms checked, with no selection for condo_bedrooms and then change the content type to "condo", the view produces nothing. Ditto for the converse. If both bedroom filters are checked (any value) it also fails for either or both content types selected.

The view always fails when both bedroom filters have selected values, regardless of which (or both) content types are selected.

I tried "ORing" the two bedroom filters but got the same results.

I tried using the Dependent Filters" module but it only hides the filter - it doesn't disable it or even reset the selection when hidden.

I tried this is D6 and D7. Tried basic filter mode (no BEF) too.

When the view works (only one bedroom filter selected) it produces this SQL:

SELECT node.nid AS nid, node.created AS node_created, 'node' AS field_data_field_house_bedrooms_node_entity_type, 'node' AS field_data_field_condo_bedrooms_node_entity_type
FROM 
{node} node
INNER JOIN {field_data_field_condo_bedrooms} field_data_field_condo_bedrooms ON node.nid = field_data_field_condo_bedrooms.entity_id AND (field_data_field_condo_bedrooms.entity_type = 'node' AND field_data_field_condo_bedrooms.deleted = '0')
WHERE (( (node.type IN  ('condo_unit')) AND (field_data_field_condo_bedrooms.field_condo_bedrooms_value = '1') ))
ORDER BY node_created DESC
LIMIT 10 OFFSET 0

When it fails (both bedroom filters selected):

SELECT node.nid AS nid, node.created AS node_created, 'node' AS field_data_field_house_bedrooms_node_entity_type, 'node' AS field_data_field_condo_bedrooms_node_entity_type
FROM 
{node} node
INNER JOIN {field_data_field_condo_bedrooms} field_data_field_condo_bedrooms ON node.nid = field_data_field_condo_bedrooms.entity_id AND (field_data_field_condo_bedrooms.entity_type = 'node' AND field_data_field_condo_bedrooms.deleted = '0')
WHERE (( (node.type IN  ('standalone_house')) AND (field_data_field_condo_bedrooms.field_condo_bedrooms_value = '1') ))
ORDER BY node_created DESC
LIMIT 10 OFFSET 0

So basically, I cannot make a filter selection on a field in a deselected content type. I would have expected the query to ignore the filter for the deselected content type, or at least not show no results for the selected content type. As you can see, Views won't even run the query for the bedroom field in the selected content type, when the bedroom filter in the other content type has a value selected. Weird.

The quickie solution is to make the bedroom fields shared, but that's a little restrictive in this case for various reasons.

CommentFileSizeAuthor
#1 view_test.txt7.37 KBdruplicate

Comments

druplicate’s picture

StatusFileSize
new7.37 KB

Also, the order of filters doesn't affect anything.

All three filters are exposed so the visitor can select the node type (house or condo) and the number of bedrooms for each.

Of course, if the node type was not exposed, you could simply use an OR arrangement with the node type filtered per OR group.

I solved this problem some years ago with D6 - Views 2, by writing a jQuery script to hide one of the bedroom filters and clear its values if the opposite node type was selected. Works well but I was hoping to find a cleaner solution in Views 3.

I've seen other issues like this at Stack Exchange, and other places and the upshot seems to be that this is an inherent limitation of Views, but it seems to me an easily remedied problem with some simple logic or option choice to disable filters for content types not included in the query. I thought that was what the Views Dependent Filters module was supposed to do, but it doesn't.

View attached.

kclarkson’s picture

I also need this support as well.

It seems to me that there are a number of issues regarding this type of filter.

From a site builder's perspective this seems to be an obvious thing that should be allowed. The filter works great when you do not expose it but once you do expose it and check the box to "limit based on the selection" it now shows you all content. Please consider druplicate's issue

druplicate’s picture

I know crossposting is generally frowned upon, but... I need to figure this out ASAP.

More on this issue
and a simplified desription of the problem.

druplicate’s picture

A hint that this behavior is inherent in Views from the readme at the Views Dependent Filters module:
---------------------------------------
The user experience is thus:

1. Load the page.
2. Select 'cake'. The cake flavour filter now appears in the exposed filter area.
3. Select 'chocolate'.
4. Submit the form to apply the filters.
5. In the refined view result, the user can unselect 'cake' and the cake flavour filter will disappear. Submitting the form at this point will take them back to the original, unfiltered view. Alternatively, selecting another type of product will let them select bicycle size or book genre accordingly.

Note that selecting *both* 'cake' and 'bicycle' will cause both the dependent filters to show, but due to the nature of Views queries, selecting values in both will not show any results! (Unless you stock a chocolate-flavoured bicycle with a 19" frame.)
---------------------------------------
In my case, only one content type can be selected at a time (exposed radio buttons), but the bug in the Views Dependent Filters module is that any selected values in the field filters don't get reset when the filter is hidden, which can happen if the visitor first selects one type, enters filter values for a field in that content type, and then selects another type without first clearing the first type's field filter values. That's what my little jQuery script took care of. At the time is was easier to write the script rather than make a custom Views filter. I filed a bug report (#1804182: Hiding filter does not reset it.) for that module but it's a ghost town over there. But even so, the module description says it's supposed to ignore any filter values if the filter is hidden - didn't work for me.

druplicate’s picture

Status: Active » Closed (won't fix)