Ask a question
So I'm working in my Bubble app and I'm making a contacts page and I've got to a point where I mean at the moment I've only got five contacts but when that number grows I will probably be looking to add in a search and this is one way to go about it using Bubbles default search box. So if I go into the editor and look for search and this acts a lot like an input field but with some other bonuses so I can update the placeholder.
Dynamic data types in search
And then out of these choices I want it to be dynamic to be able to search through my Bubble app and my contacts. So I define the list of options to contacts and then I'm going to have it search the name and this is one of the limitations and why there will 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. But 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, right? So that should work and go on to preview.
Workflow action when search result is clicked
So now if I type in Tony, I get or even the beginnings of Tony, I get Tony and 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, that's what to do. So 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 contact, when I select it, it changes the from Bubble's perspective, it changes the data in the input. So that's why I've gone with inputs value is changed and then I can do navigate and I have a really rough profile page and then to send the data, to send Tony's data or whichever contact is selected, I go this search box value. And so the value is a data type over type 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.
So 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 the default Search input element
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 limits me to only searching one search field and that can cause all sorts of problems that should be quite simple. 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.
Workaround to search across multiple fields
Now, a way around that is that when your user 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. 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 points of workarounds. And in a future video I'll be showing how to create a search box that both philtres the content here and allows you to search more than one field at a time.