Creating a Search Function in Bubble.io
I'm working in my Bubble app and I'm making a contacts page. At the moment I've only got five contacts, but when that number grows I will probably be looking to add in a search. This is one way to go about it using Bubble's default search box.
Setting Up the Search Box
If I go into the editor and look for search, this acts a lot like an input field but with some other bonuses. I can update the placeholder and then out of these choices I want it to be dynamic to be able to search through my Bubble app and my contacts. I define the list of options to contacts and then I'm going to show, I'm gonna have it search the name.
Limitations of the Default Search Box
This is one of the limitations and why there'll be a follow-up video showing another way to approach doing a search because I can only search one field here. But in another video, I'll show how to search more than one field. For now, we'll go with name and then I'll leave that one unchecked because I don't want free entry of text into the box.
Testing the Search Functionality
So that should work. Go onto preview. Now if I type in Tony I get, or even the beginnings of Tony, I get Tony. If I click on it nothing happens. So let's build a workflow now for if I click on Tony I want to be able to go to Tony's profile because this is a search box in my header and that would make sense as what to do.
Building the Workflow
I go for when an element's input is changed and it selects the search box because when I select one of the data entries that I have in context, when I select it, it changes the data in the input. So that's why I've gone with input's value is changed. Then I can do navigate and I have a really rough profile page.
Sending Data to the Profile Page
To send the data to send Tony's data or whichever contact is selected I go this search box value. So the value is a data type over typed text which is useful if you want your search box to be able to take a value that has found no results and create a result. That will be in another video, but for now we just want value because that value is of type contact.
Testing the Complete Functionality
Let's give it a refresh. Tony and now I click on Tony. It's a random photo of Unsplash for a video about profile pictures, but you can see I've gone to a page in the URL you can see that it is a page of that is profile in my Bubble editor and then this is the unique ID for Tony's entry.
Limitations of This Approach
Some flaws in this to point out and reasons why you might want to consider a different approach is if I go back this does not filter this, it doesn't allow me to do that very easily. Also, it means also it limits me to only searching one search field and that can cause all sorts of problems that should be quite simple.
Example of Limitations
For example, if you have a field of first name and a different field of last name, the default built-in search box here will only let you search one of those fields. Now a way around that is that when you use a registers you have a field called first name, a field called last name, and a field called full name and you take those details and you combine them together with a space in the middle for that third field.
Workarounds and Future Improvements
But yeah, and then you can choose it here, but it's not perfect because then every time a user updates like their first name or their last name you have to have either a back-end trigger, a workflow, or some sort of workflow that you create on the front end to ensure that if they update their last name the full name also gets updated. So it's not ideal, but those are a few pointers of workarounds and in a future video I'll be showing how to create a search box that both filters the content here and allows you to search more than one field at a time.