Search using selection buttons

Hi, I am trying to create a search where the user can select or deselect a number of Food Types by clicking on various buttons and the search then includes all Food Items that have one of the selected Food Types and displays them in a Repeating Group. I know about how to merge a number of searches in lieu of using OR. What I don’t know is how to make the search refer to the Food Types that are listed on each button (if they are clicked).

a) Should I be creating a Thing called ‘Search’ and adding each Food Type to a list in the Search thing using workflow? This would allow me to save a history of Searches, but I do not know how then to make the actual search match all the criteria contained in the ‘Search’ thing

b) Should I be putting the buttons in a separate Group, and create a custom state called ‘FoodTypeList’ which is the list of selected Food Types (via the buttons)? But then, I don’t know how to get the Custom State to update as buttons are selected or deselected, and nor do I know to get the ‘Repeating Group search’ to refer to the custom state.

c) or something else?

Thanks for your help,

Simon

Hi Simon,

b) would be the one to use, so have a custom state as a list of Food types, then a search that has a constraint of “is in” and then your list.

Except that custom state lists don’t work like data lists. You can’t “add” or “remove” elements as you click buttons. You can only set it to a list. And a list, annoyingly, isn’t a thing + thing + thing etc. I didn’t manage to get a dynamic custom state list to work.

So you can use a list on a user data (for example) which is a). Or as you say, a Search thing, which has a list of foodtypes.

An alternative would be to try to get your your selected food types into their own repeating group, then point the “is in” of the select at the repeating group.

Sorry can’t get my Chromebook to paste a screen shot, but it is the “is in” that you need here I think.

Nigel.

Ok, now I have tried creating a Repeating Group that shows all the Food Types with check boxes next to them. However I can still not find a way to get a search from another Repeating Group to show only those Food Items that have the Food Types that are checked in the check boxes. Any ideas?

Thanks

You will need to get a list of “selected Food Types” somewhere that can be referenced by the other repeating Group.

At the moment you can’t make Custom State Lists dynamic (i.e. you can’t ADD / REMOVE Food Types via an Action when you change the checkbox value) so you will have to create a temporary field to hold this on the User or a new thing. Then do a Contains in the other repeating group.

The data-based state list will allow you to do a “Checkbox’s value is changed” action that can ADD / REMOVE from the State List as you go depending on “This Checkbox is checked” or not checked to add or remove the food type.

Hi, so I am still struggling with this but have made partial progress:

I have a page with 3 repeating groups:

a) Repeating Group showing Food Types - name and a check-box. The workflow says that when a box is changed and the box is checked, it should add the Food Type to a ‘List of Food Types’ list on a new Thing called ‘Search’ - i.e., a new Search. Based on checking the box and looking at the data for Searches, this is partially working - it creates a new Search each time with only the most recently checked box’s Food Type in it - it does not make lists of more than one Food Type.

b) Repeating Group showing Searches - it is meant as a test to check that I can display the searches and track changes as I check the boxes - this seems to be working (although I can not test it with a List of Food Types due to the problem in a)).

c) A list of Food Items that refers to the current User’s last Search and only shows the Food Items where the Food Type ‘is in’ that Search - again this seems to be working but can not test with more than one Food Type selected due to a).

So, any suggestions regarding the problem in a) would be appreciated!!

Many thanks

Simon

On a) the easiest thing would be that I can have a search that returns (and displays in a Repeating Group) all ‘Food Items’ that have a ‘Food Item Type’ where the relevant check boxes are checked. Emmanuel - is this possible? Thanks.

So I think the approach in a) in your post of 5 days ago is fine: you want to add/remove things from a list that then you use for the search, using the constraint “is in”. Now I don’t think you should create a new search each time, as it takes a bit more time, but why don’t you create a custom state at the page level that is a list of Food Types, and the modify that one? That should do what you want to do I think.

I am interested in this, as I have tried to do something very similar to what Simon is doing.

But I can’t see how to do it with custom states, as you can’t add/remove something from a custom state in the way you can a database array. Unless you have changed this recently ?

Regardless of the UI event that triggers the action…how do you achieve adding a thing to a list on a custom state ?

You’re correct, my bad. we don’t enable modifying states yet. Creating a thing is probably the best workaround right now

Ok. But when I try to ad to the list of Food Types on the Search using the check box, it only adds one Food Type before creating a new Search. Or should I not be using the checkboxes, and instead using a workflow based on pressing a submit button after a number of food types have been selected from a list?

As long as the “Search” is already created, you can then add / remove from the Food Types List using “Make changes to a thing” can’t you ? Rather than creating a new thing each time ?

Yes, you can put the search as the page or group thing, which is a cleaner way to do it.

Hi guys. OK I am still finding this frustrating as it seems as though it should be so simple, and you have provided me with many useful suggestions, but I still haven’t got this working and it is totally preventing me from progressing with my project so would really welcome some help. Sorry for the long post but I added screenshots and here is the link to the page: https://bubble.io/site/lunchapedia/test_simple_search_2_0

I have tried the following based on your suggestions and with the aim of simplifying the page:

a) On ‘Page Load’, a new Thing called ‘Search’ is created with 3 attributes of:

  • ‘Done_by_User’ = ‘Current User’
  • ‘Search_Time’ = ‘Current Date/Time’
  • ‘Food_Types add list’ = ‘Search for Food Types’ (this is a list attribute)

The idea is to start with all the possible ‘Food Types’ so that the initial view will show all ‘Food Items’, then the user can narrow it down as required.

This seems to work as I can see the fields in the database (although I note that while the ‘Done_by_User’ filed appears blank in this screenshot, I can see it completed in the database table view)

The page only contains two elements:

b) A ‘Repeating Group’ that lists all ‘Food Types’ based on a search for Food Types:

This seems to work too:

c) Another ‘Repeating Group’ that list all ‘Food Items’ based on a search for Food Items where ‘Food Item Type’ is in ‘Current Page Search’s Food Types’

However this doesn’t seem to work as it returns nothing in the list even though I can see the ‘Search’ shows all ‘Food Types’ (as per screenshot above). I have checked that I have a box to display the ‘Food Item Name’ in the Repeating Group.

See right hand side of this screenshot:

Finally, the idea is that by clicking on the ‘Food Types’ listed in the left-hand Repeating Group, the workflow will i) check if the relevant ‘Food Type’ is already in the Search or not and ii) either add or remove it as appropriate

This doesn’t seem to work either - although I can not see the results in the right hand Repeating Group, I have tested it by clicking on the Food Types and checking in the database, and the Food Types are not being removed from the Search.

If you have taken the time to read this far - thank you.

All suggestions welcome.

Thanks,

Simon

My immediate thought would be that “Current Page Search” is not set to the thing you created on page load ?

Normally you “send” the thing to the page. In this case you are creating the thing, then you would need to set the page’s thing from within the page, but I don’t think you can do that ?

I think it would be better to set a custom state on the page for “Current Search” (of type search) and then reference that ?

OK I think I have got somewhere by trying Nigel’s suggestion about a custom state. I will test it a bit more tomorrow and let you know how I got on.

Thanks

Simon

1 Like