Semantic-ui: Dropdown Search Ignore Diacritics / Match Partial

Created on 29 Mar 2017  路  8Comments  路  Source: Semantic-Org/Semantic-UI

Hi there,

Is it possible to change the dropdown filter/search to ignore diacritics like "fianc猫" or "ci锚ncia", this issue comes from a long time already. Referenced in #3287 #4287 #3577

Another enhancement would be an option to match part of the string i.e.:
my search query would be: "ska"
and the results: "Alaska, Nebraska..."

for now, any workaround is welcome!

thank you

Duplicate

Most helpful comment

implementation proposal:

      exactSearch: function (query, term) {
        var diacriticsRegexByReplacement = {
          'a' : /[芒茫盲氓膩膬膮]/g,
          'e' : /[猫茅茅锚毛膿臅臈臋臎]/g,
          'i' : /[矛铆卯茂矛末墨沫]/g,
          'o' : /[贸么玫枚艒艔艖]/g,
          'u' : /[霉煤没眉农奴怒暖]/g,
          'c' : /莽/g,
          'n' : /帽/g,
        }
        query = unaccent(query.toLowerCase());
        term  = unaccent(term.toLowerCase());
        if(term.indexOf(query) > -1) {
           return true;
        }
        return false;

        function unaccent(str) {
          for (var replacement in diacriticsRegexByReplacement) {
            if (diacriticsRegexByReplacement.hasOwnProperty(replacement)) {
              var diacriticRegex = diacriticsRegexByReplacement[replacement]
              str = str.replace(diacriticRegex, replacement)
            }
          }
          return str;
        }

All 8 comments

Hi @brunotourinho, unfortunately, it鈥檚 still not here; let鈥檚 track everything in one place. On matching partials, try either this:

$('.ui.dropdown')
  .dropdown({
    fullTextSearch: true
  })

Or this:

$('.ui.dropdown')
  .dropdown({
    fullTextSearch: 'exact'
  })

Hi @Banandrew, the fullTextSearch worked great! Still waiting for the ignore diacritics option! Thanks

implementation proposal:

      exactSearch: function (query, term) {
        var diacriticsRegexByReplacement = {
          'a' : /[芒茫盲氓膩膬膮]/g,
          'e' : /[猫茅茅锚毛膿臅臈臋臎]/g,
          'i' : /[矛铆卯茂矛末墨沫]/g,
          'o' : /[贸么玫枚艒艔艖]/g,
          'u' : /[霉煤没眉农奴怒暖]/g,
          'c' : /莽/g,
          'n' : /帽/g,
        }
        query = unaccent(query.toLowerCase());
        term  = unaccent(term.toLowerCase());
        if(term.indexOf(query) > -1) {
           return true;
        }
        return false;

        function unaccent(str) {
          for (var replacement in diacriticsRegexByReplacement) {
            if (diacriticsRegexByReplacement.hasOwnProperty(replacement)) {
              var diacriticRegex = diacriticsRegexByReplacement[replacement]
              str = str.replace(diacriticRegex, replacement)
            }
          }
          return str;
        }

Hi @Vitucho! Thanks for sharing! Where do I place your code to make it work? In a separated file or just replacing the original function?

Hi @brunotourinho i just replaced the entire function, look in the semantic.js code for the function exactSearch and replace the implementation it should do the trick!!

Thanks @Vitucho! Is there any way of extensibility of this function, and not just adding it in built in code?

@Myst6971, we've been waiting for this implementation for a long time, just like the calendar. Our friend @mdehoog managed to build a separated plugin to it. Maybe we should do the same for the search parameters.

Added option ignoreDiacritics to dropdown and search module for Fomantic-UI by https://github.com/fomantic/Fomantic-UI/pull/422 :grin:
See http://jsfiddle.net/t23uewyn/

Was this page helpful?
0 / 5 - 0 ratings

Related issues

miguelmota picture miguelmota  路  3Comments

ghost picture ghost  路  3Comments

deneuxa picture deneuxa  路  3Comments

guilhermeblanco picture guilhermeblanco  路  3Comments

ghost picture ghost  路  3Comments