Ask a question
Here's a quick trick for getting the most out of using the Fuzzy Search and Auto Complete plugin by Zeroqode. If we look at just a very rough app that I started building, I want to list my contacts in this app.
Fuzzy Search with Option Set fields
And if I go into contacts, you can see that I've got a number of fields, and one of those fields is not a text field, it's currency. And currency is set up as an Option Set. If I go into Fuzzy Search here and I go for the search and also correct element that I've added to the page, I can see the fields that I can get the plug in to search through, and I can't see currency. That's because it's only going to show me fields that are of the field type of text. So I can do a search for name and email address and country because they're all text fields. But if I'm linking in with another data entry in my database, so I'm using an Option Set, I can't get the plug in to search that field. Well, you can, but with this workaround. So I'm going to create a backend workflow and it's going to be a database trigger.
So I'm going to say when currency changes, and a database trigger runs whenever an item in your database of that particular type, in this sense, contacts, whenever that is changed. Now, I don't want it to run every time, especially with workload units coming into effect very soon. I want to limit this to only when the contacts before change, which is currency, is not the contacts now currency. So that's only going to apply this workflow when the currency field is updated. And so what I can do is I can make changes to a thing and I can make changes to the contact now. And I'm going to add in the new field and call this currency text. And this is a workaround I find myself doing a lot because it allows you to express other relationships in your database as text, therefore making it searchable within the Fuzzy Search plugin.
So I'm going to then say, contact now currency. And then because it's an Option Set, the label is known as display. And so that's going to print in there, if I look at my option sets, either US dollars or British pounds. So let me demonstrate that in action.
And so a database trigger will run whether I make a change in the back end here as the app creator, or if a user makes a change on the front end. So you can see that I've got Bruce Banner here, and there's currently no currency set. But if I change currency to US dollars and then click Save, we can see that the currency text is also US dollars. And I think that there is just a slight site. There we go. If I click refresh data, it shows that it's made the change there. But if I say Bruce Banner is actually British Pounds, you can see it updates it. So if I set each of these up... That made no sense. I deliberately put Captain Britain in there to put pounds in. Let's change Bruce Banner back to USD. And Tony Stark, yeah, to USD. Okay, and then if I go back to my page, contacts, I think, I can now search by name and by the currency text. And so if I set up my repeating group of contacts for the data source to now do the fuzzy search elements matches, and then I preview it.
So if I type in Tony, we can see that I get Tony. If I type in USD, we can see we get Tony and Bruce because I can now search that text field. And remember, the beauty of doing a database trigger here is no matter how many different parts of your app you allow a user to update that field, it's always going to keep the text field in sync with the Option Set field.