Skip to content
This repository has been archived by the owner on Mar 16, 2018. It is now read-only.

IE 9 probelm with click event in dropdown for multiselect #36

Open
firulais opened this issue May 10, 2012 · 1 comment
Open

IE 9 probelm with click event in dropdown for multiselect #36

firulais opened this issue May 10, 2012 · 1 comment

Comments

@firulais
Copy link

In Firfox the plugin is working like a charm.
In IE 9 when clicking in the dropdown for selecting an item is just working correct the first time in a multiselect.
When selecting the second (or further) item for multiselect a problem arrises: The current (first selected) value is overridden and the letters typed in are joined.

Example:

  1. Typing e.g. "sc" into the input, the dropdown appears, click with mouse on "Scott Tiger". "Scott Tiger; " is copied into the item and the letters "sc" are cleared from the item. Everything is fine in IE 9 and firefox.
  2. Typing e.g. "jo" into the input, the dropdown appears, click with mouse on "John Dow". Firefox is fine, the value "John Dow; " is copied into the item and the lettes "jo" are cleared. The item now holds the values "Scott Tiger; John Dow; "

Problem in IE 9:
The item holds the wrong value "John Dow; jo"

IE 9 overrides the already selected values of the multiselect and does not clear the typed in letters for selection.

Thx a lot for some hints.

<html>
  <head>
    <script type='text/javascript' src='lib/jQuery-1.4.4.min.js'></script>
    <script type='text/javascript' src='jquery.autocomplete.js'></script>
    <link rel="stylesheet" type="text/css" href="jquery.autocomplete.css">
    <script type="text/javascript">
      $().ready(function() {
        $('#ac').autocomplete(['Scott Tiger', 'John Dow'], {multiple: true, multipleSeparator: '; '});
      });
    </script>
 </head>
  <body>
  <form>
    <input id='ac'>
  </form>
  <body>
</html>

You may try it here:
http://jsfiddle.net/t7xeY/

@qiangtou
Copy link

see
http://jsfiddle.net/t7xeY/20/
我加了下面的一行代码在828行
https://github.com/agarzola/jQueryAutocompletePlugin/blob/master/jquery.autocomplete.js#L828


<script type="text/javascript" >
        var field = this[0];
        if (field.createTextRange) {
            var range = document.selection.createRange(),
                orig = field.value,
                teststring = "<->",
                textLength = range.text.length;
            range.text = teststring;
            var caretAt = field.value.indexOf(teststring);
            field.value = orig;
            this.selection(caretAt, caretAt + textLength);
            caretAt == -1&&(caretAt = orig.length - 1); 
//add code here
caretAt == -1&&(caretAt = orig.length - 1); 
            return {
                start: caretAt,
                end: caretAt + textLength
            }
        } else if (field.selectionStart !== undefined) {
            return {
                start: field.selectionStart,
                end: field.selectionEnd
            }
        }
    };
})(jQuery);
</script>

now work well in ie9.
有一个问题,在选第一个词时,用鼠标点击是好的,按回车键则光标会跳到最前面,在选第二个词以后,没有这样的问题。

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants