I am trying to filter a "sub-category" dropdown menu based on another "category" dropdown menu based on this example: https://www.youtube.com/watch?v=Lhq8X7m0Xic
We have a "Category" database, and a "Sub-Category" database that has a reference field for "Category".
Currently, when a user selects "Accessories", they are not able to select a sub-category.
export function dropdown3_change(event, $w) { subcategoryfilter(); } function subcategoryfilter() { $w('#dataset3').setFilter(wixData.filter() .contains("category", $w("#dropdown3").value) ); }
The code seems to be fine, however is a little bit of more code needed when working with references, compared to simpler field types.
The issue is that you are trying to filter Sub-Categories Dataset by title of Category. It is so because Category dropdown value is Title of the category, and filter requires it's ID.
Here is updated snipped:
async function subcategoryfilter() { // retrieve all items from the Category dropdown const categories = (await $w("#dataset2").getItems(0, 20)).items // get ID of currently selected Category const selectedCategoryId = categories[$w("#dropdown3").selectedIndex]._id $w('#dataset3').setFilter( wixData.filter().eq("category", selectedCategoryId) ) }
Hope this helps!
Hi Dustin,
can you share a link to your site?