Difficulty Enabling Finding Objects by Tags

I’m having a hard time implementing some functionality. First, a little bit of background:

I’ve got a few different kinds of things:

  • Users
  • Data
  • Tags

I’ve also got some things that are acting as join tables:

  • Users2Data
  • Data2Tags

So users can have many data objects, and those data objects can have many users. Similarly with tags: a data object can have many tags, and a tag may apply to many data objects.

I’ve done it this way because I’d like to implement a social component later that can track the prevalence of certain data objects and tags across the user-base as a whole. The “join table” approach is a holdover from how I’d solve the problem in something like Rails or Meteor; my apologies if it’s not the Bubble way.

The functionality that I’m having a difficult time with is letting the user select a group of tags and displaying only the pieces of data that have all of the tags selected; right now, it displays all of the pieces of data that have at least 1 of the tags selected. The approach I’m currently using is:

  1. User selects a tag
  2. Tag is added to a list of tags contained in the current user object (couldn’t think of another way to implement this in Bubble)
  3. List of data objects displayed is updated: I search for all Data2Tag entries where the tag is in the list of tags contained in the current user object and I search for all User2Data entries where the user is the current user

I have a few ideas as to how to implement this, but I can’t quite figure out how to fit them into a Bubble workflow. I was thinking one of the most promising would be if I could search for a list of all data objects through User2Data with user = current user and then convert the tags from all of the associated Data2Tag objects to a list on a per data object basis, I could compare that resulting list of tags with the list of tags contained in the current user object.

I’m having a hard time with the “per data objet basis” part. Any suggestions or tutorials that I might find helpful? Thanks in advance.

Hey @startupjam201702 :slight_smile: It sounds like having a custom state (that is a list of texts) would be best to use for the search. Custom states are remembered at the page-level, and don’t use any workflows since you’re not making changes to the database. This way, a User can select certain tags which are added/removed from the custom state list of texts; and the repeating group constraint would be that the item must contain all of the selected tags. There are a few posts in the forum which discuss creating a custom state list, but feel free to share a link to your app and I can definitely assist in setting this up!

1 Like

Thanks @fayewatson! I’ll take a look at custom states; I glossed over them in the past because they initially looked pretty intimidating. When I get it working using custom states, I’ll mark this as the solution. :smiley:

1 Like

Sounds great! :smiley: Let me know if you have any questions!

A great way of going about this is to have your tags all displayed as buttons.

Adding a tag:
When each button (I.e. Tag) is selected the button text is added to the custom state (ex. “SelectedTags” which is a list of texts). In the workflow, you’d do this by setting the custom state SelectedTags=SelectedTags plus item: This button’s text).

Removing a tag:
If the user deselects the button (tapping it again), you run a workflow that sets SelectedTags equal to SelectedTags:filtered …and inside the filtered option, select “Advanced” and set that condition to does not contain current buttons text.

Then you just set a repeating group to “do a search for” the data your interested in with the condition that it “contains SelectedTags”.

There are a one or two examples (not many) of this on the forum, buts it’s great UI/UX method of using of custom states for searching tags.