list.js icon indicating copy to clipboard operation
list.js copied to clipboard

Search words with accents? ^~

Open marcelcaferati opened this issue 4 years ago • 6 comments

Is there a functionality that makes it possible to match words with accents?

Example, I have a list of users, one user is called "Antônio" with he ^ simble on the first O. Is there a way to ignore that? Make it so the search understand the ô as simply an "o" and returns the item?

marcelcaferati avatar Nov 04 '20 17:11 marcelcaferati

There is undocumented support for custom search functions, so you could write your own function to do this.

YZirkind avatar Nov 04 '20 17:11 YZirkind

thanks for the answer friend!

It is still unclear how do I start the list with my custom search function.

If I simply call listObj.search(['name'], searchFunction) after starting my list var listObj = new List('users-mobile', options), it will just run the "search" function once, it is not clear to me how to make the list always use the custom search everytime someone types in the input.

Is there a way to do it?

marcelcaferati avatar Nov 05 '20 16:11 marcelcaferati

It is not currently possible to instantiate List.js with a custom search function. You would have to add an event listener to your search field to run your custom function.

YZirkind avatar Nov 05 '20 18:11 YZirkind

What I did some time ago

  • use a Javascript function to latinize the string, replace accents to latin characters, like https://gist.github.com/najlepsiwebdesigner/5822511
  • in list.js
    • prepare.setSearchString() after .toLowerCase() add s = s.latinise();
    • search.values() after .toLowerCase() add text = text.latinise();

mmokross avatar Nov 05 '20 20:11 mmokross

This might also help: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize#Compatibility_normalization

YZirkind avatar Nov 05 '20 21:11 YZirkind

What I did some time ago

  • use a Javascript function to latinize the string, replace accents to latin characters, like https://gist.github.com/najlepsiwebdesigner/5822511

  • in list.js

    • prepare.setSearchString() after .toLowerCase() add s = s.latinise();
    • search.values() after .toLowerCase() add text = text.latinise();

Can you explain this in a more detailed way? I am kind of new to JS

Thanks!

marcelcaferati avatar Jan 07 '21 17:01 marcelcaferati