It's currently not possible to filter by a multi-value field.

I have 2 webform elements I'd like to expose as a filter on my view. One is a mulitvalue text box, the other an entity select.

If I remove the !$element_plugin->hasMultipleValues($element) condition on line 31 of src/WebformElementViews/WebformDefaultViews.php then a filter for the multivalue text box can be added to the view and seems to work perfectly.

On the other hand, while the entity select filter now appears in the list that can be added to the view (with the above change), it does nothing when clicked. Just fails silently somewhere...

Comments

stella created an issue. See original summary.

stella’s picture

Status: Active » Needs work
StatusFileSize
new612 bytes

Attaching a patch for the change I made anyway, just so everyone is clear on what change I made to get multivalue text fields filterable.

I assume multivalue fields were excluded for a reason though...

robpowell’s picture

StatusFileSize
new23.71 KB

@stella this worked for me and my multivalue text field. I did however have an issue with setting the value for the filter. When I select is equal to no textfield displays for me to enter the value I want to filter on.

milos.kroulik’s picture

I have the same problem as #3. However, there is already issue created for this. See https://www.drupal.org/node/2861942

  • bucefal91 committed 46438d8 on 8.x-5.x authored by stella
    Issue #2864749 by stella, robpowell: Not possible to filter by a multi-...
bucefal91’s picture

Status: Needs work » Fixed

Huh... that 's funny. I was the one who put that extra condition about non-multiple. The reason I put it there is because it might produce duplicate rows. Consider you have a multi-value text field on your webform called "Name". I would submit there 2 values: "Alex" and "Alexander". Then if you go and build a webform view and filter by condition "name contains alex", it will match twice the submission and correspondingly will display it in 2 rows of the view. I thought that wasn't exactly nice, so I prevented filtering by multi-value until I come up with a solution.

Today I was exploring possible venues on how to solve it, and closer to the end of brainstorm session I said.. heck.. Let's see how core behaves in the same scenario with Fields. So I attached a "Name" textfield with multi-value to "article" node, created a node with "alex" and "alexander". And to my surprise the view also showed the same node in 2 rows of the view. Basically core did not solve this problem. It can be solved by introducing aggregation into the query and I guess core expects site builders to solve it that way whenever it becomes a real problem.

All in all, Stela, your patch turns out to be the most appropriate one :) Thank you for the patch :) It is now committed.

Status: Fixed » Closed (fixed)

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