3

I'am having problem with jquery selector.

Here is;

Jquery Selector (new):

    <script>
  (function ($) {
            jQuery.expr[':'].Contains = function(a, i, m) {
  return jQuery(a).text().toUpperCase()
      .indexOf(m[3].toUpperCase()) >= 0;
};

  function filterList(header, list) {
    var form = $("<form>").attr({"class":"filterform","action":"#"}),
        input = $("<input>").attr({"class":"filterinput","type":"text"});
    $(form).append(input).appendTo(header);

    $(input)
      .change( function () {
        var filter = $(this).val();
        if(filter) {

          $matches = $(list).find('a:Contains(' + filter + ')').parent();
          $('li', list).not($matches).slideUp();
          $matches.slideDown();

        } else {
          $(list).find("li").slideDown();
        }
        return false;
      })
    .keyup( function () {
        $(this).change();
    });
  }
  $(function () {
    filterList($("#form"), $("#list"));
  });
}(jQuery));
  </script>

The List:

<div class="normal" id="form"></div>
    <li>İngiltere</li>
    <li>Iraq</li>
    <li>Argentina</li>

When typing "i" to input box "İngiltere" does not appear. Only "Argentina". I have to make a modification to search both "i" and "İ" when typing "i" to the box..

Thanks..

new_coder
  • 103
  • 2
  • 9
  • 4
    Pretty sure that's not a capital `I`. At least not on an en-us keyboard. – Deryck Jan 20 '14 at 16:03
  • 1
    @Deryck I think it's a special character issue but unsure at the moment as OP mentions capital i(I) which clearly is not İ – Huangism Jan 20 '14 at 16:04
  • 1
    "İ" is turkish char. For example translation of England is İngiltere. So filtering country list is pain in the ass with this problem... – new_coder Jan 20 '14 at 16:09
  • You might be interested in this: http://stackoverflow.com/questions/286921/efficiently-replace-all-accented-characters-in-a-string – Tomalak Jan 20 '14 at 17:00

1 Answers1

0

For this immediate problem you can solve it by doing this:

First make sure the existing <li> items don't have that character. If they do, you'll need to run:

$('#form li').each(function() {
    $(this).text($(this).text().replace(/\u0130/g, "I"));
});

Here is what should happen


But either way, you'll need either this:

Replace your .keyup( function () { .... code with this:

.keyup(function(e) {
    var charCode = e.keyCode || e.which;
    if (charCode === 304) {
        $(this).val($(this).val().replace(/\u0130/g, "I"));
    }
    $(this).change();
});

Or you can use that replace() in the change() method (just before trying to filter it out).

PS - I can't test this since my keyboard isn't Turkish but try it and if it fails, let me know.

Deryck
  • 7,608
  • 2
  • 24
  • 43
  • When i did this the search form div dissappeared. – new_coder Jan 20 '14 at 16:29
  • OK try again with both pieces of code. Just had to get the replace code right (forgot the 0 lol) – Deryck Jan 20 '14 at 16:33
  • This will probably not work without first putting thought into the logic of the code placement since I'm not really sure based on this what data is already available when the page loads and what is created dynamically. – Deryck Jan 20 '14 at 16:37