Hi,

"the value of any exposed filter of the view being filtered

The last option makes the exposed filter dependent on the other filter."

Can you explain how this can be done.

I have 2 exposed filters:
1 for board types and one for fin types. For both these i have created the separate entity reference views and they show only those terms that have nodes. Thank you and that works fine!!

Now after filtering by boards, can we make only those fins show up in the next exposed filter based on the filtered values of the first filter?

Thank you!
Jaya

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

maximpodorov’s picture

Yes, it's possible. Just enter the first filter identifier as "Arguments for the view" setting of the second filter (surrounded in [] brackets).

j4’s picture

Hi Maxim,

Sorry for replying so late, i was trying to understand before i wrote back to you again, but am afraid I am still stuck.

So my first filter identifier is "boardtype". I am afraid i do no understand the second half of the sentence. Is this in the main view that has the exposed filters? In the contextual filters part?

Sorry for this! Thanks in advance!
Jaya

maximpodorov’s picture

You have two filters: master and dependent. You need to know master filter identifier (e.g. field_master). When you configure the dependent filter (which is Views Reference Filter), you must enter [field_master] in the "Arguments for the view", and create new view which receives one argument (which will be the current value of the master field), this view must be selected in "View used to select the entities" in the dependent filter configuration.

maximpodorov’s picture

Status: Active » Postponed (maintainer needs more info)

Have you solved your problem?

ReBa’s picture

Hi,

for me, this is also somewhat sketchy on what to do exactly. I'm trying to get this dependent filter working, but it doesn't seem to work.

Following content types:
Season
Competition ( Entity reference: Season)
Matchday (Entity reference: Competition)

I made a view where I can view my matchdays with following filters:
Matchdays filter criteria

With dependee filter "Season":
Filter season

And Dependent filter "Competition"
Filter competition

Following is my contextual filters for the entity_reference view:
views_reference contextual filters

An example of my exposed filters:
Exposed filter (season)
Exposed filter (competition)

The thing is when I'm looking at my entity_reference view argument I don't see anything:

function mytheme_views_pre_render (&$view) {
  if($view->name == 'references_view') {
    dpm($view->argument);
  }
}

Views array

Hoping to inform you enough, I would like to know whether this is a bug, or is it me that is implementing it wrong?

Thanks in advance!

ReBa’s picture

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

Title: Dyncamic dependant filters » Dynamic dependant filters

Could you check whether AJAX call is performed when the master filter is changed?

tistou’s picture

How to check whether AJAX call is performed?
I followed the instructions, but the list of options for dependent filter is not updated. Only after I press Apply button it's updated.

maximpodorov’s picture

Use Network tab of web development tools of your browser.

ReBa’s picture

Does it needs an AJAX call then? My page just refreshes...
If the page gets refreshed after applying the first filter, shouldn't the second filter automatically get it's argument from the first filter?

My second filter gets "All" as argument, always.

maximpodorov’s picture

Oh. Could you disable page reloading after changing the first filter (turn form autosubmit off)?

ReBa’s picture

The response:

[{
    "command": "settings",
    "settings": {
        "basePath": "\/",
        "pathPrefix": "nl\/",
        "ajaxPageState": {
            "theme": "kvk",
            "theme_token": "Cc0cagWk3s-hU619uOUkv5Hx7x03iTBFzfeAIWD-0mM"
        },
        "colorbox": {
            "transition": "elastic",
            "speed": "350",
            "opacity": "0.85",
            "slideshow": true,
            "slideshowAuto": true,
            "slideshowSpeed": "2500",
            "slideshowStart": "start slideshow",
            "slideshowStop": "stop slideshow",
            "current": "{current} of {total}",
            "previous": "\u00ab Prev",
            "next": "Next \u00bb",
            "close": "Close",
            "overlayClose": true,
            "maxWidth": "75%",
            "maxHeight": "75%",
            "initialWidth": "300",
            "initialHeight": "250",
            "fixed": true,
            "scrolling": true,
            "mobiledetect": false,
            "mobiledevicewidth": "480px"
        },
        "entityreference_filter": {
            "views-exposed-form-competition-admin-matches": {
                "view": "competition_admin\/matches",
                "args": [],
                "dynamic": {
                    "field_competition_target_id_entityreference_filter": ["field_season_target_id"]
                }
            }
        }
    },
    "merge": true
}, {
    "command": "entityreference_filter_insertnowrap",
    "method": "html",
    "selector": "#views-exposed-form-competition-admin-matches [name=\u0022field_competition_target_id_entityreference_filter\u0022],#views-exposed-form-competition-admin-matches [name=\u0022field_competition_target_id_entityreference_filter[]\u0022]",
    "data": "\u003Coption value=\u0022All\u0022\u003E- Any -\u003C\/option\u003E\u003Coption value=\u0022583\u0022\u003E  Regular competition 2015 - 2016 \u003C\/option\u003E",
    "settings": null
}, {
    "command": "invoke",
    "selector": "#views-exposed-form-competition-admin-matches [name=\u0022field_competition_target_id_entityreference_filter\u0022],#views-exposed-form-competition-admin-matches [name=\u0022field_competition_target_id_entityreference_filter[]\u0022]",
    "method": "trigger",
    "arguments": ["liszt:updated"]
}, {
    "command": "invoke",
    "selector": "#views-exposed-form-competition-admin-matches [name=\u0022field_competition_target_id_entityreference_filter\u0022],#views-exposed-form-competition-admin-matches [name=\u0022field_competition_target_id_entityreference_filter[]\u0022]",
    "method": "trigger",
    "arguments": ["chosen:updated"]
}, {
    "command": "invoke",
    "selector": "#views-exposed-form-competition-admin-matches [name=\u0022field_competition_target_id_entityreference_filter\u0022],#views-exposed-form-competition-admin-matches [name=\u0022field_competition_target_id_entityreference_filter[]\u0022]",
    "method": "trigger",
    "arguments": ["change"]
}
]

So there happens something... but only for the field_season_target_id, I don't get any responses to change the competition select box.

My form setup:
Form setup

maximpodorov’s picture

I think everything works. What is the problem?

ReBa’s picture

The problem is that my second (dependant) select is not being updated...

maximpodorov’s picture

Could you try the latest version? I fixed some bugs there.

MrsWho’s picture

For anyone beating their head against this same issue like I was, I found a hint in another issue: the preview screen does not show the desired behavior of these screenshots, but it DOES work on the view page itself (or pane, in my case). See screenshots below.

Reference filter View Contextual filter
Exposed Reference filter settings
 Doesn't work
 Does Work

One note on the Contextual Filter settings for the Reference Filter View: I did not want this view (country) to show up at all unless the user had already selected the parent filter (region), hence my configuration:

WHEN THE FILTER VALUE IS NOT AVAILABLE: Display contents of "No results found"

Hide View did not work for me in this use case: it hid the view no matter what the parent filter selection. No results hid it only when a region was not selected.

If you do this, you will not see the dependent filter in the preview AT ALL due to the default checkmark "Hide filter if empty." I unchecked this item just for this screenshot just for demonstration purposes. However, for production, I will check it so that the country selector is not shown at all unless it is populated per the region selected.

adigunsherif’s picture

Read this comment with full concentration to each point mentioned if you are still having issues with this, more importantly, number 2