Discussion:
[autocomplete] Incorrect selection on mouse click in IE7+
vsc
2009-10-09 10:11:32 UTC
Permalink
For clarity, I have modified the code in the demo application to
demonstrate the bug.
1. Please download code from http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/
and place attached AutosuggestBug.html in demo folder.
2. Launch AutosuggestBug.html in Internet Explorer (I used version
IE7).
2. In "Multiple Cities (local)" text area enter letter "a" (Observe
autosuggest list displayed with focus on Aberdeen)
3. Press enter (to add Aberdeen)
4. Enter letter "a" again (Observe autosuggest list displayed with
focus on Aberdeen)
5. Select Ada (the second entry in auto suggest list) with a mouse
click.

Expected Result:
The "Multiple Cities (local)" text area should be populated with
Aberdeen, Ada (as is the case with Firefox).

Actual Result:
In IE, the "Multiple Cities (local)" text area is populated with Ada,
a.

Additional information:
On debugging the code, the problem seems to be in the following
snippet of code:

selectCurrent() {
...............
if ( options.multiple ) {
var words = trimWords($input.val());
if ( words.length > 1 ) {
var seperator = options.multipleSeparator.length;
var cursorAt = $(input).selection().start;
...........
if (cursorAt <= progress) {
wordAt = i;
return false;
}
.......
});
words[wordAt] = v;
.......
v = words.join( options.multipleSeparator );
}
v += options.multipleSeparator;
}

$input.val(v);
......
}

The problem occurs primarily at:
var cursorAt = $(input).selection().start;
Here, the variable, 'cursorAt' holds an incorrect value of -1 (return
value from the selection() function) when selection happens via mouse
click in IE.

NOTE: This problem happens only in IE.

Has somebody encountered this problem and/or have a recommended
solution to this problem?
Any help will be appreciated.

Regards,
Charanya



Attachment:
AutosuggestBug.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/
TR/html4/strict.dtd">
<html>
<head>
<title>jQuery Autocomplete Plugin</title>
<script type="text/javascript" src="../lib/jquery.js"></script>
<script type='text/javascript' src='../lib/jquery.bgiframe.min.js'></
script>
<script type='text/javascript' src='../lib/jquery.ajaxQueue.js'></
script>
<script type='text/javascript' src='../lib/thickbox-compressed.js'></
script>
<script type='text/javascript' src='../jquery.autocomplete.js'></
script>
<script type='text/javascript' src='localdata.js'></script>

<link rel="stylesheet" type="text/css" href="main.css" />
<link rel="stylesheet" type="text/css" href="../
jquery.autocomplete.css" />
<link rel="stylesheet" type="text/css" href="../lib/thickbox.css" />

<script type="text/javascript">
$().ready(function() {
$("#suggest3").autocomplete(cities, {
multiple: true,
matchContains: true,
autoFill: false
});

});


</script>

</head>

<body>

<div id="content">
<form autocomplete="off">

<p>
<label>Multiple Cities (local):</label>

<textarea id='suggest3' cols='40' rows='3'></textarea>
<input type="button" value="Get Value" />
</p>

</form>
</div>
</body>
</html>
Rye
2009-10-09 15:19:33 UTC
Permalink
Great plugin, but I cannot believe there are not more threads on this
topic.

This issue can be clearly seen on autocomplete's demo here:
http://jquery.bassistance.de/autocomplete/demo/

Using IE (works as expected in FF) try entering values into the
Multiple Cities (local): text box. The selected option is added to the
beginning of the list in proper case as well as to the end of the list
in lowercase. Other stange things happen if you select options
beginning with the same letter. If you hold down shift when selecting
your options it appear to act as expected.

Any help would be much appreciated.

Does anyone have a fix for this in IE?
Post by vsc
For clarity, I have modified the code in the demo application to
demonstrate the bug.
1. Please download code fromhttp://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/
and place attached AutosuggestBug.html in demo folder.
2. Launch AutosuggestBug.html in Internet Explorer (I used version
IE7).
2. In "Multiple Cities (local)" text area enter letter "a" (Observe
autosuggest list displayed with focus on Aberdeen)
3. Press enter (to add Aberdeen)
4. Enter letter "a" again (Observe autosuggest list displayed with
focus on Aberdeen)
5. Select Ada (the second entry in auto suggest list) with a mouse
click.
The "Multiple Cities (local)" text area should be populated with
Aberdeen, Ada (as is the case with Firefox).
In IE, the "Multiple Cities (local)" text area is populated with Ada,
a.
On debugging the code, the problem seems to be in the following
selectCurrent() {
...............
if ( options.multiple ) {
var words = trimWords($input.val());
if ( words.length > 1 ) {
var seperator = options.multipleSeparator.length;
var cursorAt = $(input).selection().start;
...........
if (cursorAt <= progress) {
wordAt = i;
return false;}
.......
});
words[wordAt] = v;
.......
v = words.join( options.multipleSeparator );}
v += options.multipleSeparator;
}
$input.val(v);
......
}
var cursorAt = $(input).selection().start;
Here, the variable, 'cursorAt' holds an incorrect value of -1 (return
value from the selection() function) when selection happens via mouse
click in IE.
NOTE: This problem happens only in IE.
Has somebody encountered this problem and/or have a recommended
solution to this problem?
Any help will be appreciated.
Regards,
Charanya
AutosuggestBug.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/
TR/html4/strict.dtd">
<html>
<head>
<title>jQuery Autocomplete Plugin</title>
<script type="text/javascript" src="../lib/jquery.js"></script>
<script type='text/javascript' src='../lib/jquery.bgiframe.min.js'></
script>
<script type='text/javascript' src='../lib/jquery.ajaxQueue.js'></
script>
<script type='text/javascript' src='../lib/thickbox-compressed.js'></
script>
<script type='text/javascript' src='../jquery.autocomplete.js'></
script>
<script type='text/javascript' src='localdata.js'></script>
<link rel="stylesheet" type="text/css" href="main.css" />
<link rel="stylesheet" type="text/css" href="../
jquery.autocomplete.css" />
<link rel="stylesheet" type="text/css" href="../lib/thickbox.css" />
<script type="text/javascript">
$().ready(function() {
        $("#suggest3").autocomplete(cities, {
                multiple: true,
                matchContains: true,
                autoFill: false
        });
});
</script>
</head>
<body>
<div id="content">
        <form autocomplete="off">
                <p>
                        <label>Multiple Cities (local):</label>
                        <textarea id='suggest3' cols='40' rows='3'></textarea>
                        <input type="button" value="Get Value" />
                </p>
        </form>
</div>
</body>
</html>
Rye
2009-10-12 18:32:41 UTC
Permalink
OK. For anyone else who is tearing their hair out over this one...

It would appear that the earlier version of this script works fine in
relation to the problem above.

You can grab v1.1pre here:
http://view.jquery.com/trunk/plugins/autocomplete/jquery.autocomplete.js

You can link to the demo from here:
http://docs.jquery.com/UI/Autocomplete#Demos

Clarification of the problem
=======================

Try the Multiple Cities (local): in IE and it works just fine:
(v1.1pre)
http://view.jquery.com/trunk/plugins/autocomplete/demo/

Try the Multiple Cities (local): in IE and it does not work (v.1.1):
http://jquery.bassistance.de/autocomplete/demo/

It does seem to be related to the Selection function when triggered
via a mouse click rather than via 'Enter'. If the author could get the
multiple feature working as it did in v1.1pre in the most recent v1.1
version it would be excellent! There are also far too many versions of
autocomplete flying around in cyberspace.

Thanks in advance authors.

Rye
Craig Heneveld
2010-02-19 20:32:36 UTC
Permalink
I have a fix for this issue on jQuery Autocomplete plugin 1.1. The file is
attached.

I commented out the return false on line 222 and added a putCursorAtEnd()
function, so that after selecting an autoComplete item it moves the cursor
to the end of the field (IE fix).

http://old.nabble.com/file/p27659902/jquery.autocomplete.js
jquery.autocomplete.js
--
View this message in context: http://old.nabble.com/-autocomplete--Incorrect-selection-on-mouse-click-in-IE7%2B-tp25819409s27240p27659902.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.
Loading...