I have a list of schools whose names are both English and French (these are schools in Canada, where we have two official languages):

  • Avondale Public School
  • École secondaire Jean-Léger
  • Samspon Street High School
  • École de la Vache Sacrée
  • (etc.)

I'd like to be able to type "ecole", not "école" into the Chosen widget, and have all the entries that start with "école" show up in my listing. Right now, if I type "ecole", Chosen tells me that "No results match 'ecole'." Due to sloppy inputting skills (and especially due to the many english-speakers who don't even know how to get the French accented characters on their keyboard), many people are going to be confused by this.

Basically, I want to be able to type "e", and have Chosen know that I mean any of "e", "è", "é", "ê", or "ë". (And of course I'd want similar mappings for other letters that can have accents on them.)

Any ideas on how to deal with this?

Comments

dan3h’s picture

I found a thread about this, over at the Chosen library's (not the drupal module's) issue queue:

https://github.com/harvesthq/chosen/issues/536

dan3h’s picture

Found a solution. A bit of hacking, but it works.

  • Copied onto clipboard the code from https://github.com/harvesthq/chosen/issues/536#issuecomment-26087459
  • Opened up chosen.jquery.js
  • Pasted the code over top of the function definition for AbstractChosen.prototype.winnow_results and AbstractChosen.prototype.search_string_match

Then, on the drupal-module side:

  • Opened up chosen.module and found chosen_library() function
  • Changed it to use chosen.jquery.js instead of chosen.jquery.min.js

If someone has a more elegant way of doing this (i.e. not having to hack both a library and a module), please do share.

Dave Reid’s picture

Status: Active » Closed (won't fix)

Yeah, this is outside the scope of what the module can do. This is a Chosen library issue.

fakir22’s picture

dan3h's solution #2 is the best so far. As said before, this issue is related to Chosen library and sadly the solution is not merged yet into official Chosen release...

Therefore, there is a sligthly better way to do this so you have to hack only the library, NOT the module.

  • Open up chosen.jquery.js
  • Replace the 3 functions "AbstractChosen.prototype.stringEscaped", "AbstractChosen.prototype.winnow_results" and "AbstractChosen.prototype.search_string_match" with the ones provided by felpasl
  • Copy/Paste the entire code from chosen.jquery.js into an javascript minifier (like javascript-minifier.com)
  • Paste the minified output into chosen.jquery.min.js

That's it. Problem solved and you can update Chosen drupal module without loosing the changes on library's side.