emposha / FCBKcomplete

Jquery facebook like(fancy) multi-select
http://www.emposha.com
383 stars 115 forks source link

filter_case to false doesn't really do an case insensitive search. #62

Closed ketwaroo closed 13 years ago

ketwaroo commented 13 years ago

Basically if you have a list of items salt,sock,sand belt,somersault,etc. and you type "S" upper case S, you have nothing matched. It's on the master branch. I'm guessing the latest revision.

I sort of did a quick and dirty fix on it by adding a regex search. in jquery.fcbkcomplete.js around line 519. in the cache object.

        'search': function (text, callback) {
          var temp = new Array();
          $.each(element.data(), function (i, _elem) {

            if(options.filter_case)
                reg = new RegExp(text,"g");
            else
                reg = new RegExp(text,"gi");

            if (typeof _elem.search === 'function') {
                if (_elem.search(reg) != -1) {
                  temp.push({'key': i, 'value': _elem});
                }
            }
          });
          return temp;
        },
emposha commented 13 years ago

thanks for fix. new version pushed can you test it?

ketwaroo commented 13 years ago

aah. I'm pretty stupid. I edited the code I submitted. very sorry about that. I was just leaving work and in a hurry.

the problem was actually that the case insensitive search wasn't working. Uppercase characters were not matching lowercase counterparts and vice versa.

ketwaroo commented 13 years ago

so, yeah. it's

            if(options.filter_case)
                reg = new RegExp(text,"g");
            else
                reg = new RegExp(text,"gi");

instead of

            if(options.filter_case)
                reg = new RegExp(text,"i"); // this should be just a g modifier instead of i
            else
                reg = new RegExp(text,"gi");
emposha commented 13 years ago

ok changes pushed ;) (actually it`s my bad, i should check it before push)

ketwaroo commented 13 years ago

Also, a fix for itemIllumination to hilight the correct letters when filter_case is used. There was a try catch block in there. Not sure if it's useful.

      function itemIllumination(text, etext) {
          try {
            var regex = new RegExp("(" + etext + ")", (options.filter_case) ?"g":"ig");
            var text = text.replace(regex,'<em>$1</em>');
          } catch(ex) {
          };
        return text;
      }
emposha commented 13 years ago

added.