Conditional Filtering: Filter only when a tag is selected

Completely new with Bubble here, sorry if this is basic.

I have a RG with books in them. Each book has different levels of categories that they can be filtered with. The filters (categories) are in the form of tags and multiple tags can be selected. And there are two levels of tags - Level 1 and Level 2. The moment a tag is clicked, I have a custom state that adds the category value to the custom state ‘selectedL1’ or ‘selectedL2’ depending on which level of category was selected.

I have then filtered the RG data source such that only those books are shown whose list of categories/tags intersect with the tags in the custom state for each level.

image

The problem here is that if none of the tags of Level2 are selected, then I just want filtration to be done on Level1 tags. So if the custom state does not contain any tag for a given level, then filtration should not happen for that level. Filtration should happen only when a tag is selected.

Example: If i have selected ‘Antifiction’ in L1 and none in L2, I want all books tagged to L1 be shown. If I have selected ‘Antifiction’ in L1 and ‘History’ in L2, I want the list to be filtered for both. But right now if i do not select anything from Level 2 i do not see any books since the custom state for L2 ‘selectedL2’ is empty and the filter does not return any value as both the filters are applied.

I need to add another level of category after this so I would really appreciate if someone could guide me here.

Here’s my read-only project link for you to understand better in case I wasn’t clear here: The Antilibrary | Bubble Editor

2 Likes

@SerPounce I know you’re a guru with repeating groups and filters, any ideas on this one?

I would probably default to having a custom state on the repeating group for each combination of level filters. I’m away from my computer at the moment, but I’ll think about it a bit more.

1 Like

See that “Ignore empty constraints” checkbox?

2 Likes

What Keith said.

1 Like

Thanks for the response Keith and @SerPounce

I did check the “Ignore empty constraints” box but in vain. There’s virtually no change in the preview and everything works as when the box was unchecked.

Could I be missing something else? Thanks again!

Thank you Andrew for the reply and bringing more help!

I did think of having multiple custom states that show or hide the RG based on what’s selected, but with each new level the states would increase non-linearly and I thought maybe it’s inefficient and will lead to slowing the site down… Let me know if I’m worng? Thanks again!

Try using conditionals to change the data source.
So, condition 1 says if L2 is empty then use the first search.
Condition 2 says if L1 is empty then use the second search.
etc.

5 Likes

Yes! it worked. Didn’t know that was possible. Thanks a ton!

1 Like

Awesome, glad you got it sorted.

Hi @SerPounce @keith @andrewgassen @kaushikvatsal ,

If it is L1,L2,L3…L20…; There will be too many combinations of these. It takes hundreds of conditions to change the data source.

I am looking for an alternative way. I really need help. If anyone has a recommendation it would be great.

Check “daisy chain” filtering:

And video with some details about it from @Andrew.Vernon:

Makes your life much easier when you have tons of filters.

1 Like

Wow, that was super awesome. Took me a min to get my head around it, but once I got it, makes so much sense! Thank you for sharing and taking time to make the video.

I did struggle to show a “loading” element while one of my filters (which is a difficult one to process on a lot of data) processes the filter. I tried to “show” a loading Popup at the beginning of the daisy chain and hide it at the end, but the custom event taht does the hard filter triggers the next event even though it is not finished, Bubble goes through the whole daisy chain so fast that it never actually shows the “loading” popup. It does show if I debug step by step though. The same would happen with a customs state…

I can’t put a condition on “when RG is loading” because it’s the filtering of the “Display in RG” action that takes some time.

So I’m left with when someone clicks a certain checkmark and it takes the app 20 seconds to do all the filtering, there is no way to display to the user that that the filtering is “in process and please wait until it is done”

Any ideas?