gch1p / bootstrap-5-autocomplete

autocomplete/typeahead js plugin for bootstrap v5
104 stars 36 forks source link

This does not work with accented characters such as ú #8

Closed simon-stewart closed 2 years ago

simon-stewart commented 3 years ago

To get it to work for searchs with accented characters and accented items, you can add:

const removeDiacritics = function(str) { return str .normalize('NFD') .replace(/[\u0300-\u036f]/g, '') }

and apply this in lines doing searches using indexOf such as

const idx = removeDiacritics(item.label).toLowerCase().indexOf(removeDiacritics(lookup).toLowerCase());

and

if (removeDiacritics(item.label).toLowerCase().indexOf(removeDiacritics(lookup).toLowerCase()) >= 0) { items.appendChild(this.createItem(lookup, item)); if (this.options.maximumItems > 0 && ++count >= this.options.maximumItems) break; }

gch1p commented 2 years ago

Thank you!