Using Fuzzy Search and Autocomplete in a Reusable element

Following up this closed thread, I have a solution that works for me:

The problem outlined there is that the Fuzzy Search and Autocomplete plugin requires that the ID of the search bar is unique on the page. If you embed this into a reusable and place it more than once on a page (as may well happen in an SPA-like build) then you’ll find that only one of the reusables will work.

To get around this:

  1. Install the Keystroke Input Trigger plugin Keystroke Input Trigger Plugin | Bubble

  2. In your reusable, drop in an “input monitor” in alongside your existing search bar and Fuzzy Search.

  3. Now create two Custom States on your reusable; one called Search Bar ID, and one called Search Text. Both of these should be type Text. Set the Search Bar ID default to something.

  4. On your Fuzzy Search, UNTICK Set Text To Match from an Input Box, and set the Text To Match to the Search Text custom state on your reusable:

  5. Set the ID on your Input Element to the Search Bar ID custom state.

  6. Set the inputmonitor (the new plugin you dropped in at step 2) to bind to the Search Bar ID custom state.

  7. In the reusable’s workflows, we’re now going to randomly generate the ID. So, go to the Workflow pane and create a “General → When Condition is True” workflow. Set it to run when your search bar is visible. Make sure you leave it to only happen once!

  8. In the workflow, add an “Element Actions”->“Set State” and set the Search Bar ID custom state to “Calculate Formula”->“Generate Random String”, setting it to 30 characters including everything except for special characters.