What am I doing wrong in setting up this filter?

This is better because you will reduce a lot your condition. This will be easier to manage. And if you add new filters, you will just need to add it to the search and not change each condition.
Because actually, what you need to do to avoid conflict is to set a perfect setting for ALL conditions and ALL possibilities. Imagine if you have 2 conditions this mean you can have
Field A is empty AND B is empty
Field A is empty AND B is not empty
Field A is not empty AND B is empty
Field A is not empty AND is not empty.

Not, what if you have 3 conditions?
A, empty, B, empty C, empty
A not empty, B empty, C empty
A not empty, B not empty, C empty
A not empty, B empty, C not empty,
A not empty, B not empty, C not empty… (and continue for all others possible combinations!)

But all of this can be avoided using the Ignore empty constraint.

2 Likes

@jici is exactly right with this. If you check ‘Ignore empty constraints’ and make your sort order dynamic you should be able to do all these searches you have the 30 conditionals for with a single search.

Essentially, the Ignore empty constraints simply says 'Hey, if Dropdown Category is not empty then we will filter by that constraint. Otherwise we’ll ignore the category constraint entirely."

And you only need one checkbox to be able to change the sort order dynamically. Here’s an example.

image

This simply says If the Checkbox Price (low to high) is not checked then this value is yes, if it is checked then this value is no.

I’m fairly certain its the LAST valid conditional that is triggered not the most complex.

2 Likes

Ok @Jici, so last night I created a custom state that ported my 3 variables in the conditional and set the custom state to “yes” when all three were true.

Then I simply created a conditional that relied upon the custom state being “yes”

And it worked!!

It seems as if bubble doesn’t like when you are using too many “ands” in a conditional that are of varied element types (in this case 3). I thought that was a breakthrough, but I see what you are saying with having to do way too much work to individually write these expressions as 30+ conditionals.

This is exactly what I’ve been doing and it’s been driving me crazy because as you mention, it IS a ton of work. I have decided to delete all the conditionals and start from scratch with this more efficient route until I get it right.

@Jici and @Eli I am trying the empty constraint route and for some reason nothing shows.
Also, if I am sorting dynamically by checkbox, how do I specify that I want it to sort by price? Is there a trick to that?

The first thing I want to show when page is loaded is all products in current user’s favorite categories (electronics, clothing, sporting goods). Then when the user searches / filters it should show all products in the relevant category and location. All circumstances should be able to be sorted by price low to high or high to low, as the default will be last created I believe.

I tried to apply a conditional that when the location and category fields are empty it would by default show all products in the user’s favorite categories. I don’t seem to have that right either.

Clearly still not doing it right as it’s not working :tired_face:

It’s not going to show anything like that as Bubble can’t find a field to sort by called No or Yes. For this, you don’t want set the Sort by field dynamically (though that can be done, it’s a different topic).

Leave the ‘Sort by’ set to Price.

Set the ‘Descending’ dynamically using the same logic you are currently using in the Dynamic field name. Like this:

image

Also, the second Sort by is unnecessary. The first will sort Descending if checked and Ascending if not checked. (I would consider radio buttons or a dropdown to keep a user from being able to select both sort high to low and low to high concurrently)

Good luck! Filtering and sorting gave me a beating for a long time as well :slight_smile:

PS - If you get desperate, pm me a link to your editor and I’ll set it up for you!

1 Like

“Dynamic field name” catches everyone out :slight_smile:

1 Like

@Eli thanks for this and the continued explanation (and the offer). Filtering is indeed kicking my ass, ha. I’m following and have set things up how you described, and it is working great.

I am now using the radio buttons. At first I didn’t want the search to default to “price low to high” as I wanted it to be by “created date”, but I think your setup is more straightforward to initially sort price low to high, and then when the radio is hit for “high to low” it sorts descending.

Is there a way I can have a radio button option pre-selected (price low to high)? Right now when you load the page it starts empty (but the RG is sorted low to high anyway). I tried to do this through default value but that seems to only set the value, and not the selection.

Next, here’s the category dropdown that is pulling dynamically from data type “category” which is linked to specific products. At the top of the dropdown there is this empty space.

1.) Can text be filled in there, like “My Favorites”, since that is the default search

2.) Is there an easy way to be able to provide an “All Products” option? Is the best way to do this to add a new Category called “All Products” and then put a conditional on the RG that when the dropdown’s value is “All Products” to make the RG do a search for all products? Or is there an easier way to do this?

Good morning @marktuff, glad it’s finally working! To set the default in your radio buttons simply add the text ‘Price (low to high)’ in the default field rather than an expression. As long as the text there exactly matches one of the options, it will be set by default.

Your solution to the All Products question is a great way to handle both of these. Add a My Favorites option and an All Products option to your dropdown and then set the ‘This input should not be empty’ option to yes so that you don’t have an empty option at the top.

Then your default search could be by category with two conditional searches for All Products and My Favorites. As long as My Favorites is set as the default in the dropdown this will operate exactly the same as having the default search be for Favorites with a conditional for searching by category.

1 Like

Morning again @Eli, I went ahead with the plan it all works exceedingly well and smoothly!

From 30 conditionals down to three, thank you to you and @Jici for all the support on this thread. Hopefully this helps others out too. I’m sure I have plenty more to learn around filters, but this was a good intro to advanced, and I’m starting to understand it a bit better.

Here is “My Favorites” and “price low to high” showing as the default selections in the dropdown and radio button.

Here’s the dropdown in action… Question relevant to this is what is the best way to custom order the dropdown to put “My Favorites” and “All Products” up top and then the rest going alphabetical? Would that be to create another field in the “Category” data type called “order” of type number, and give a number to each category in the order I want the categories to display in the dropdown? 1, 2, 3, 4, 5, etc.

Setup for “My Favorites” as default.

Conditional setup for displaying “My Favorites”

Conditional setup for “All Products”

That’s all the conditionals. Down to 3. Hooray! :champagne:

2 Likes

Awesome! That looks great @marktuff!

Yes, exactly! However, only add a number to the categories you want to have at the top of your dropdown choices.

While you can add a number to all the categories and simply sort by the Order field this creates duplication that must be managed. For instance, suppose you want to add a new category in the future called Brain Parts. This will fall right between Beauty & Health and Clothing which means all the Order fields for every category greater than Brain Part in an alpha sort will have to be changed. (you could use decimals but you get the idea)

We already have the sort order we need aside from the top My Favorites and All Products.

Make the Order fields for those categories 1 and 2 and leave the Order field blank on the rest and set the search to sort first by Order and then by Name. Like this:

image

Now you can create additional categories in the future and they will automatically sort alphabetically without having to manually concern yourself with what the sort order number should be and do you need to change the Order number on other categories.

This has been fun! Glad it’s working for you!

2 Likes

@Eli , brilliant!

When I set it up the first time the duplicity crossed my mind but I was so happy to get it working in the first place I didn’t drill down into the solution yet, and you already provided an answer. Thank you!

This makes awesome sense. I just set it up exactly the way you demonstrated in your screenshot, and it works like a charm.

Order
1, 1
2, 2, 2, 2, 2, 2. 2, 2, 2…

Ha, glad this is fun for you! It’s turned more fun for me lately too as the information sinks in!

1 Like

@Eli Ok, a new situation and new problems.

I am now trying to integrate a fourth element – a keyword search – run by the search and autocomplete plugin to continue to filter these results, but I am not getting it to work the way I want. Are you familiar with this plugin?

Here is how I updated my setup.

However, when I have the dropdown on “All Products” and type into the keyword searchbox nothing happens. On second look it appears the search may be stonewalled because I have a conditional set to search all products when “All Products” is the value in the dropdown, and this may take precedent over the initial conditional.

When I make the dropdown "electronics’ it shows no results when there should be 4.

When I do a keyword search and have the dropdown on “electronics” it starts showing and filtering results. This seems strange to me as I have the conditionals set to “OR” for the inputs and not “AND” – so I’m not sure why the “Electronics” search in the previous screenshot would yield no results and this one does.

When I add location to the mix, the search appears to work as expected continuing to drill down on MacBooks categorized as “electronics” in Boston.

My brain and these filters :expressionless:

Questions I have.
1.) Is there a way to add the search and autocomplete matches into the “search for” constraints in the first conditional. That would seem to me to be the easiest route, but I tried a few expressions to no avail as I didn’t quite know how to write the proper expression, or if it is possible.

2.) Or do I need to add more conditionals to the RG search for when “All Products AND Searchbox Autocomplete Input are not empty” to return search results. “My Favorites” AND Searchbox Autocomplete input are not empty"… It would seem this route is falling back into the bad habits when I had 30 conditionals, but I’m not sure if there is another way.

Any help, again, would be appreciated!

This makes sense as you are using ‘intersect with’ and since there are no results from the Search & Autocorrect there are no items intersecting.

I’ve only used Search & Autocorrect a few times so I’m no expert by any means but I did a set up very similar to yours last summer.

Basically I duplicated my default and conditional searches over to the Search & Autocorrect element and then made my RG’s default data source the Search & Autocorrect matches.

image

Then I moved my initial default search over to a conditional on my RG that simply said if the keyword input is empty do the same search here instead of through the Search & Autocorrect element and then added that condition to the conditional searches on the RG as well.

Looking back through it now, for easier management I should have used a single hidden RG ‘variable’ with the basic default and conditional searches defined and then fed that data to the Search & Autocorrect element and to the visible RG for when the keyword is empty but it works fine like it is.

It would be a lot simpler if the Search & Autocorrect had an option to ignore itself if the search box value was empty but it doesn’t at this point.

Like I said, I’m no expert with Search & Autocorrect so there may be a way to do that differently but that’s how I used it.

Hi @Eli, morning again!

Problem for me here is that I want to show the users’ “favorite categories” by default and not the searchbox matches.

You’re right about the intersect. Doh. I had it different before but that didn’t work either. I’m curious as to why merging the searches and using “unique elements” doesn’t’ return any search results either? What am I not seeing with this one?

Not sure I follow what “hidden RG variable” means…?

This, or if it were somehow possible to make it part of the constraints.

Unless they are using the keyword search to filter their favorites, correct? Then you need it to be filtered by the Search & Autocorrect element.

I may have been unclear with my setup and it was more complicated than it needed to be.

I reconfigured it slightly this morning and its working perfectly.

Put the exact same default search and conditional searches on both the Search & Autocorrect and the Repeating Group. Then added an extra conditional to the RG that says if the Keyword input is not empty use the Search & Autocorrect matches. Put this conditional at the very bottom so it’s guaranteed to trigger if the condition is true.

These matches will give you the same result as the RG searches (since the searches are the same on the Search & Autocorrect) they are just filtered through the Search & Autocorrect element.

(Side note, could it not have been named something simpler?)

Anyway, it looks like this on my search:

Morning again @Eli!

That’s correct.

Just tried this and even that didn’t return any results. Man, this is frustrating.

**UPDATE: Just tried again, but tried something different and it appears to be working now.

I changed the conditional trigger from the keyword input not being empty to Search & Autocorrect matches count > or = to 1… Then setting the data source to the matches, and incorporating the price sort.

I’m not even sure I’m following how it’s possible that this is working, haha. It seem as though when you are calling the Search & Autocorrect matches through the conditional it automatically intersects it’s own matches with the identical conditional data sources set on both the RG and the S&A.

I thought if I put the S&A matches as the last conditional on the RG it would only return matches for keywords, but I did not expect it would also keyword search the conditional data sources, and return the values in both but it appears that it does… so I suppose no need then for “merge”. I’m a little miffed, but I think we might be in business here. I suppose I’ll just roll with it :cowboy_hat_face:

Roll away, brother! But that’s why you put the same default and conditional searches on the S&A element as you do on the RG as it will return the same results filtered through keywords if the keyword input has a value. A search is a search is a search whether its in an RG, an S&A, or any other element. And yes, no need for merge :slight_smile:

Word of caution, this is not good UX as it doesn’t accurately represent a search that has no results. If a user types in “aaaaaaaaa” it will appear as though results are being returned (even though there are none) since the S&A element matches count will be 0.

Since the count is 0 (i.e. not equal to or greater than 1) the condition that returns keyword matches will be ignored and your search will be performed directly on the RG.

If there are no results matching the keyword, you want to show no results.

I would change that bottom condition to ‘input Keyword’s value is not empty’.

@Eli, you are totally right, thanks for the tip there.

I didn’t even think of that since it does filter up front.

But then shows everything after a certain point.

Here it is working properly.

I finally figured out why I couldn’t filter before without using the S&A matches as opposed to the input field… I was using the wrong input field (arg!).

Once I set the proper input field to “is not empty” it worked well. The search is a little laggy up front and takes a second or two for the search to load (almost seems like it won’t work), but then when it loads it’s pretty quick.

1 Like