Search/Filter for Multiple Item Reference Field

Hello,
I continue my journey into filtering a photo gallery based on a selection of tags in a dropdown menu. I got it to work using this code when the “tags” field in dataset1 is a TEXT field.

export function filterInput_change(event) {
$w(“#dataset1”).setFilter(wixData.filter()
.contains(“tags”, $w(“#filterInput”).value));
}

However, I have made the “tags” field into a multiple item reference field type, and now the filter doesn’t work. Essentially, I want it to take the value of the dropdown down, and see if that value is contained within an entry’s multiple item reference field “tags”

So here is what the data looks like:


So on the site, when a user picks “Still Life” from the the dropdown, the gallery would be filtered to only photos that have “Still Life” in the Tags field. In this case with only two photos, only the photo of the skull would be displayed.

Any thoughts? You all are awesome, by the way. This forum is incredibly helpful.

Cheers

1 Like

Anyone out there? :slight_smile:

Working through this myself.

I’m also working on a similar project if anyone has advice… thanks in advance!

I’m also working on this… I’m starting to think it’s just not possible to use a multiple item reference field in a query. Anyone have any ideas?

I am trying to accomplish this as well…
Still no one able to help with this? :frowning:

Hey there, I was FINALLY able to figure something out. I had such a hard time getting any help on this.

So what I ended up doing was adding a new rich text field to my primary table, and then setting up a hook to copy my multiple reference field data into the new rich text field. Then I made sure the query included the values of the rich text field. The tricky thing was trying to get the multiple reference data to copy over and actually retain its data rather than just showing up as an [object Object].

Here’s what I used for my hook. “search” is the rich text field, “categories” is the multiple reference field. Then you just include “search” in your query.

export function EventPhotos_afterQuery(item, context) {
item.search = JSON.stringify(item.categories)
return item
}


Good luck! I had such a hard time finding any answers or help for this, I’m sure this isn’t the best solution but it’s the best I could come up with. I was really discouraged with trying to get any answers on the forum.

I believe the solution is using hasSome() and hasAll().

Check: https://www.wix.com/code/reference/wix-data.WixDataFilter.html#hasSome

Does somebody still need help with the code ?

hey
its my first day with corvid this code worked fine for me

wixData.query( “dataset1” )
.contains( ‘nameoffield1’ , ‘value1’)
.or(wixData.query( “dataset1” )
.contains( ‘nameoffield1’ , ‘value2’))
.find()
.then( (results) => {

    // add here code that link repeater to results.items  
//something like  $w( "#chatlist" ).data= results.items; 
}); 

HOPE IT WILL HELP SOMEONE