ConorWebb96 / bb-type-ahead

A component used for querying tables, searching through results, selecting and then saving selected items back to the db.
8 stars 2 forks source link

Search by substring within a name #4

Closed miguelou7 closed 1 year ago

miguelou7 commented 1 year ago

Hey @ConorWebb96 ! This is a fantastic plugin and is very much needed in Budibase. It provides critical functionality, without it we would probably not use Budibase! Thanks!

With that said, and using it in production, we ran into an issue that's more of a feature request. I'll explain with an example.

We have a form, and a typeahead selector to choose a "Courthouse" from the table "Courthouses" (about 200 rows). Awesome.

Courthouses are named like this: "Courthouse of District A"; "Courthouse of the City of District B", etc.

So, for the user, remembering the exact name of a courthouse is not easy, they have all similar verbose names.

Therefore, when the user wants to search in the typeahead selector for a specific courthouse, the user just types "District A". This renders no results, as of now (this is the behavior I'm seeing), because typeahead does the search for text using the exact string from the beginning (like "Starts with" searches). Therefore, the user is forced to search "Courthouse of District A" to select the courthouse of his choice, but this is really hard as it's impossible to memorize the exact name of all courthouses.

Is there any way that I'm not aware of, for the search bar of the typeahead selector to search for any substring within a name, instead of just searching the substring in the beginning of the target string?

Hope I was clear enough!

ConorWebb96 commented 1 year ago

Hey @miguelou7,

Thank you for reaching out!

Yes this would be a great way to enhance the plugin.

I do think that this may be something that I won't be able to do as the search thats used to generate the results heavily ties into the Budibase API. (Meaning it may need some core changes to get it to work) I'll have a look anyway sometime next week and see if there are anything I can do and get back to you here.

If I find that this is something I can add, would you be ok with an additional setting e.g. a select that allows you to choose the type of search you wish to do. It would be similar to how filtering works on data providers. (Is in, equals, like etc.)

Again thank you for your suggestion.

miguelou7 commented 1 year ago

Hey @ConorWebb96, that's precisely what's needed!

I actually was able to create a filter in another view (using the standard selector), using the "Like" comparison, which searched through all text and gave me the desired behavior (but for a different context, a table). This is very much needed in typeahead to be able to do the same in forms.

Your proposed solution (having the additional setting to select "type of search") is exactly what I would want :)

Thanks for the fast response!

ConorWebb96 commented 1 year ago

Hey @miguelou7,

Sorry that this took so long, I have an update for you. I've added logic to allow for the filtering you wanted. You now have 2 options on standard fields; Equals and Contains. Contains should be the functionality you wanted. This should be available on the newest version v1.2.0.

This will only work when searching on normal fields, I didn't have the time to look into array searching. I hope this is enough!

Screenshot 2023-08-30 at 08 30 52
miguelou7 commented 1 year ago

Amazing! I'm going to try it out at tell you how it goes :) You rock!