Hi!

First of all congratulations for backdrop. It is an amazing piece of software, I am totally loving it. 

I am trying to make something very simple. I have a content type called "Instituciones" (Institutions), and I want a view that displays all "Instituciones", but has a exposed filter in which the user can select to filter these instituciones by the "comuna" (county) they are in. Of course, "comuna" is one of the fields for content type "instituciones".

I create the view, and filtering by taxonomy works fine, but I just can't make the filter work with a "comuna". I have tried also filtering with a plain (not exposed) filter, and get the same (no) results. I here attach some screenshots. Please let me know if something else is needed. Thanks!

Accepted answer

Hi geoma, I think your views filter doesn't work because technically it's not searching for the name of the comuna / county but for a number (i.e. the node id of the referenced content item). You can verify this by looking at the available operators. Apart from "Is equal to" there are probably operators like "Is greater than" and similar ones which don't make sense in textual content.

To filter for the name of the comuna / county, you first have to add a 'Relation' to the referenced entity in the right column of your view. Then add a filter criterion "Title" and configure it to use the relationship. Once you've done this, the filter should work, be it with the operator "Is equal to" but also with textual operators like "Contains" or "Contains any word".

Most helpful answers

Thanks geoma.  Your first post was more comprehensive than many first posts; I just needed to clarify.

Please share a screenshot of the config for that exposed filter as I'm not sure why that error appears.

An alternative approach, given that either a select box won't work, or it will be unwieldy, is an autocomplete filter; such a module exists and works, but hasn't yet been released (I will chase the maintainer again).

  1. Go to https://github.com/backdrop-contrib/views_autocomplete_filters
  2. Click the green "Code" button
  3. Right-click on "Download Zip"
  4. Copy link address

In Backdrop, go to install modules, then click Manual install and paste the url into "Install from a URL"

Comments

Hi geoma

Welcome to Backdrop.  Thank you posting detailed screenshots. As your field is an entity reference field, go into the field settings for field_insta_comuna and scroll to the bottom. Make sure this check box ("Render Views filters as select list") is selected:

Does the comuna field refer to a separate content type, a taxonomy vocabulary or a custom entity?

Thanks!

comuna is a content type. Sorry if my first post was confusing in this matter. Here goes the screenshot

I checked "Render views filter as select list", but  I get "The operator is invalid on filter: Content: Comuna." (There are over 100 entries for comunas, in fact, about 346.

Thanks geoma.  Your first post was more comprehensive than many first posts; I just needed to clarify.

Please share a screenshot of the config for that exposed filter as I'm not sure why that error appears.

An alternative approach, given that either a select box won't work, or it will be unwieldy, is an autocomplete filter; such a module exists and works, but hasn't yet been released (I will chase the maintainer again).

  1. Go to https://github.com/backdrop-contrib/views_autocomplete_filters
  2. Click the green "Code" button
  3. Right-click on "Download Zip"
  4. Copy link address

In Backdrop, go to install modules, then click Manual install and paste the url into "Install from a URL"

Olafski's picture

Hi geoma, I think your views filter doesn't work because technically it's not searching for the name of the comuna / county but for a number (i.e. the node id of the referenced content item). You can verify this by looking at the available operators. Apart from "Is equal to" there are probably operators like "Is greater than" and similar ones which don't make sense in textual content.

To filter for the name of the comuna / county, you first have to add a 'Relation' to the referenced entity in the right column of your view. Then add a filter criterion "Title" and configure it to use the relationship. Once you've done this, the filter should work, be it with the operator "Is equal to" but also with textual operators like "Contains" or "Contains any word".

You are right, that was it... Now my problem is I would like users being able to select from pre-established options, like a drop down or maybe an autocomplete. For that I would the Autocomplete Filter @yorkshirepudding tells me about?

Olafski's picture

Glad it works for you!

Regarding selecting options, I've just tested the Views Autocomplete Filters module and got it working after I had a look at the README and made sure to use the same title instance for field and filter. (There may be different title instances: the original one, and one of  the relationship.)

From the README:

If you have more titles fields defined in fields and/or filters the correspondence between field & filter must be right. For example: if field is title_2 then also the filter field should be title_2.

Olafski's picture

See also my screenshot of a view with Entity Reference relationship (right column) and a filter which uses the relationship:

Here goes the screenshot for the exposed filter config

I will try the module you are telling me about. thanks again!