I'm using the Ajax.Autocompleter component, which works great - except ampersands in some browsers. The problem is that instead of printing the ampersand sign into the search field, it acts as an 'up' arrow in the ajax suggestion list. This makes my users unable to write names with ampersands into the search box.
http://github.com/madrobby/scriptaculous/wikis/ajax-autocompleter
Specific behavior cases:
If I try to type the ampersand into my search field before the list with suggestions is shown, the ampersand gets added to the search field and all is well.
If I try to type the ampersand after the suggestion list is already visible, it will navigate to the end of the list instead, and nothing will get added to the search field (Chrome).
If I repeat this scenario in IE11, it will also navigate to the end of the list, but also add the ampersand to the search field. However, the ajax search will not get triggered in this case - the suggestion list will remain as it was before I hit the '&' key, regardless of the fact that the search field not ends with a &.
Firefox just adds the '&' char to the search box and refreshes the autocomplete suggestion list. As I would expect.
By trial and error, I noticed that:
- When I open F12 in chrome, and debug the javascript, the ampersand gets printed instead of navigating through the suggestion list. When the debug is off it doesn't print anything and navigates instead.
- If I use ctrl+v to paste the ampersand into the search field, it works fine in all browsers. On the other hand left alt + 38 does the things mentioned above, same as normal key.
My code:
<input name="searchTxt" id="searchTxt" type="text" autocomplete="off" />
<div id="autocompleteResults" style="display:none;border:1px solid black;background-color:white;text-align:left;"></div>
<script type="text/javascript" language="javascript" charset="utf-8">
new Ajax.Autocompleter('searchTxt','autocompleteResults','someUrlToGetAutocompleteResults', {});
</script>
The only clues I was able to find so far are pretty weak:
- Someone having a vaguely similar ampersand problem in chrome and youtube search https://productforums.google.com/forum/#!topic/chrome/mpt4fkaAQPg
- Another StackOverflow thread regarding Ajax.Autocompleter, but fairly unrelated How do I make an Ajax.Autocompleter perform a request without typing?
Any help is appreciated - I'll get into studying the Ajax.Autocompleter project in more detail, but since this seemed it might also be something browser-related, I asked with hopes that someone might have at least a partial answer.