valor-software / ng2-select

Angular based replacement for select boxes
http://valor-software.github.io/ng2-select/
MIT License
675 stars 587 forks source link

Accent Insensitive option #865

Open eestein opened 6 years ago

eestein commented 6 years ago

Hi, today ng2-select is differentiating from letters with and without accent. Is there a way to fix that? I'd like my searches to be accent insensitive. How could I do that?

Thanks.

Zatch3 commented 6 years ago

I need that too. Here's an idea to get this to work... Basically I made a small hack on the pipe and filter function of the component. First I defined this variables:

var a_accent = '[a|á|à|ä|â]'; var e_accent = '[e|é|è|ë|ê]'; var i_accent = '[i|í|ì|ï|î]'; var o_accent = '[o|ó|ò|ö|ô]'; var u_accent = '[u|ú|ù|ü|û]'; var n_accent = '[n|ñ]'; var y_accent = '[y|ÿ]';

Then I replaced the the letters on the original text

query = query .replace(new RegExp(a_accent, 'g'), 'a') .replace(new RegExp(e_accent, 'g'), 'e') .replace(new RegExp(i_accent, 'g'), 'i') .replace(new RegExp(o_accent, 'g'), 'o') .replace(new RegExp(u_accent, 'g'), 'u') .replace(new RegExp(n_accent, 'g'), 'n') .replace(new RegExp(y_accent, 'g'), 'y');

Finally I changed them back

value = tmpValue.replace(new RegExp(common_1.escapeRegexp(query) .replace(new RegExp('a','g'), a_accent) .replace(new RegExp('e','g'), e_accent) .replace(new RegExp('i','g'), i_accent) .replace(new RegExp('o','g'), o_accent) .replace(new RegExp('u','g'), u_accent) .replace(new RegExp('n','g'), n_accent) .replace(new RegExp('y','g'), y_accent) , 'gi'), '<strong>$&</strong>');

I'm unsure this is the best way to do it, but this worked for me at least locally...

eestein commented 6 years ago

hey, thanks for your message. I'm sorry the delay I was on vacation. The problem with that approach is that after every new version you'd need to re-do it...

It'd be nice if this was incorporated to the plugin instead.

cristianpoleyJS commented 6 years ago

+1