josefarias/hotwire_combobox

Feature request: Transliterated search

dylandamsma opened this issue · 3 comments

Hi José,

Thanks for building this - much appreciated over TomSelect.
I do have one request, but maybe you happen to know a better approach.

I am based in Vietnam and currently building an app for the Vietnamese market. Provinces follow Vietnamese spelling, like:
Đắk Lắk or Bình Thuận

I want to be able to use these original (correct) names as label, but search on transliterated version, so that typing: Dak Lak also brings up Đắk Lắk.

Right now, there's the option to set a display value and a value in itself. However, I can't set a search value.

{ display: option.first, search: I18n.transliterate(option.first, locale: :vi), value: option.last }

It would be nice to do something like this, where what I enter and search gets transliterated and would match.

Let me know if I am thinking wrong about this and/or if this is possible.

Best regards and good work!

I realized this might be doable through an async box with custom partial rendering.

Is there a way I could contribute some examples to the documentation?

It also was not so obvious that the name of the partial is the method.

I.e states/_state creates a variable "state" that I can use in the partial like state.name.

But I have a clashing partial (_user) for user search, so I named the search result partial: users/_user_result - it took me a while and reading your source code to realize I then need to use "user_result.name"

Hey @dylandamsma,

Your best bet in this case is to do the filtering server-side in an async combobox.

There's an undocumented way to decouple the display from how the list is filtered on the front-end. But then you can either match on the transliterated text or on the Vietnamese spelling, but not both.

If you want to match on both I'd suggest transliterating the search param (params[:q]) as well as the searchable text (before saving to your database, or, certain fulltext search services offer this already) and filtering server-side. Then you can stream the filtered options to the front-end. The docs contain info on how to do that.

Let me know if that doesn't work for you. Closing this in the meantime.

Thanks!

Ah, we cross-posted! 😄

I think this might be too specific of an example to add to the docs. But we could be more clear about how render_in works. I have plans to improve that soon since we just added combobox_display and combobox_value as convenience accessors in render_in partials.