Hello, I have a problem. I hate redundancy.
I have built a nested category tree by two collections: parent categories and subcategories. The category title field is reference field in subcategories collection, so I can asign a parent category to each subcategory. On the site I made two dropdowns: for parents and subs.
Now the problem appears: I want to filter subs by parents, so when in parent you choose one, for example fashion, then in subs dropdown you will only see subs like jewelry, clothing etc.
I made a filter on the subs dataset by the arents dataset and title field. But it doesn’t work at all. When I choose whatever in the parents dropdown, in the subs dropdown I get only the same wrong subs, its like the subs dropdown didn’t know, what parent I have chosen, it takes the subs of the first parents record.
Please help. Is it a bug or I just need a code to let one dropdown know what I have chosen in the other one ? Shouldn’t it know, if I filtered it by the other’s dropdown dataset ?
There is also some code trigered by on change property on the parent’s dropdown, but when I removed this code for a while, the problem didn’t disapper, so I think that dataset filter is independent on any triggering property. I am not a programmer at all, I hoped to do it visually in wix, I even have seen a video on this somewhere out there, but now I can not find it.
Greets,
Derek
The tutorial Filtering One Dataset by a Second Dataset should be able to help you figure out how to do what you want.
Thank you Yisrael, I have seen this. It is not about filtering one dataset by another. It is about filtering one dropdown value by another dropdown’s value where both dropdowns are based on separate datasets.
What my brain without programistic logic managed to come up with, it is that the subcategories dataset was filtered as per tutorial you linked, but it doesn’t know, what is value of the dropdown based on referenced dataset. Its datasets linked, not the dropdowns. As far as I know, there is no visual way to link dropdowns, so one knows, what the other shows, you have to code. I have no idea how to do it. My unprogramistic brain doesn’t have logic to combine different pieces of code and doesn’t even know which should. I think I need a piece of code that takes value of first dropdown and puts it into the subcategories dropdown and then filters its values to show only those matching the parent category. Please help.
Yes Yisrael, I did exactly whats in this article and it doesn’t work. I wrote above why probably and what I think I need:
What my brain without programistic logic managed to come up with, it is that the subcategories dataset was filtered as per tutorial you linked, but it doesn’t know, what is value of the dropdown based on referenced dataset. Its datasets linked, not the dropdowns. As far as I know, there is no visual way to link dropdowns, so one knows, what the other shows, you have to code.
You might want to consider checking out the WixArena - it’s a hub where you can look for Wix Code (and other) experts for hire.
I found a code that should filter the second’s dropdown dataset by the choice of the first dropdown, where lists of both datasets come from separate collections. Exactly my case and it should do the trick:
import wixData from 'wix-data';
$w.onReady(function () {
});
export function locationStateDropDown_change(event, $w) {
$w("#dropdownName2").enable();
locationCityFilter();
}
function locationCityFilter (){
$w("#dataset").setFilter( wixData.filter()
.eq("fieldkey", $w("#dropdown").value)
);
}
It is made by Code Queen and it is public on their website here: https://codequeen.wixsite.com/dropdown/code
But it doesn’t work on my site, the second dropdown doesn’t show any items on the list.
Is anybody here who used this and it works for him or her ? Any suggestions please ?
Anything should be tweaked, changes, anything on the site that can make this code not to work ?
Cheers
Derek
​
I was just gona reccomend the same thing. Code Queen Nayeli’s Conditional Dropdown Filters tutorial. Very concise and explicit, step by step!
I am having exactly the same problem
If you’re having exactly the same problem, then you should be able to solve the problem with the links provide above.
Please add your own issue into a new post instead of bumping up an old post.