How to make Chosen ignore accents in the search?

3

I'm using Chosen in my forms, but I'd like it to ignore the accents when filtering.

For example: In a city listing, filter it correctly to:

- africa

But it does not filter for (as words differ by accent):

- africa

On the project's GitHub, there have been discussions about this since 12/03/2012 ( link ), but have not yet implemented this in the official code.

Reading the existing discussions, I found this working example, posted by @felpasl :

However, I intend to implement it, but without changing the original source code, to minimize future complications when updating the code from the official repository.

I thought of replacing the method externally, but I can not do it. Below the code I tried, to override the method ...

var Chosen = $('#campo_select_com_chosen').chosen();
Chosen.prototype.search_string_match = function (search_string, regex) {
    alert('Método substituído com sucesso');
};

But I get this error:

  

Uncaught TypeError: Can not set property 'search_string_match' of undefined

My problem is how to replace a method of the lib I'm using without changing its fonts. If it were in PHP I would inherit the class and override the method ... but in JavaScript I do not know how to do it.

Can anyone help me on how to do this implementation, type PlugIn, in Chosen?

    
asked by anonymous 14.01.2017 / 23:30

1 answer

2

In StackOverflow in English you had a similar question, and there is an open issue in GitHub requesting this change.

In this issue there are several users putting ways to change the code, one of them posted in this Stack response and should solve your problem.

You are in JSFiddle: link
It should run importing just below the Chosen on account of prototypes.

Or if you want a more direct solution, in the last answers in the Issue the user Hanoii created a version of Chosen that is able to do this type of search: link

Question : link
Issue : link

    
15.01.2017 / 05:04