rniemeyer / knockout-jqAutocomplete

knockout-jqAutocomplete is a Knockout.js plugin designed to work with jQuery UI's autocomplete widget.
MIT License
49 stars 20 forks source link

Double quotes are not recognized without adding a leading \ #9

Open cryptc opened 9 years ago

cryptc commented 9 years ago

I'm not certain if this is a bug, or an artifact of my implementation, but I must type a leading backslash in order to match on double quotes. To get around this, I can add a filter. Code below...

Note: I have a local array of key-value pairs in $root.productGroups

<input size=45 data-bind="jqAuto: {
    value: $root.SelectSearchValue,
    source: $root.productGroups, labelProp: 'Key', 
    filter: $root.ChooseItemsFromSearchTerm, 
    options: { delay: 350, minLength: 3 }
  },
  value: ''" />

function ChooseItemsFromSearchTerm(item, searchTerm) {
    // ?bug? where double quotes aren't recognized without typing a leading backslash
    searchTerm = searchTerm.replace(/\\\"/g, "\"");  // remove a backslash from searchTerm
    return item.Key.indexOf(searchTerm) > -1;
}

Example: item (as a key-value pair): { Key: "Men's Tactical Research 6\" Khyber", Value: "15733" } value typed in text field : Men's Tactical Research 6" required value typed in text field without fix: Men's Tactical Research 6\"

So, as I type in the textbox, the moment I type a double quote I will NOT match on any items, unless I type a leading backslash, first. While my filter "ChooseItemsFromSearchTerm" fixes this issue, I thought it might be a bug with string-based search-term matching in jqAutocomplete.