views:

201

answers:

1

Heya,

I have just implemented the excellent jQuery UI autocomplete.

http://jqueryui.com/demos/autocomplete/

There is a strange bug in IE 8 (and maybe other versions).

When you select an item from the box of suggestions in IE 8 the cursor moves to the begining of the textbox before the suggested word which has just been inserted.

Firefox put the cursor after the inserted word.

Does anyone know of a fix for this?

Regards

Steve

+1  A: 

Try adding the following code into the select event that is passed to the autocomplte function.

So if you have:

jQuery('someval').autocomplete({
        source: availableTags
    });

Change it to be:

jQuery('some_val').autocomplete({
    source: availableTags,

    select : function(event, ui){
            if(document.selection) { 
                this.focus(); 
                var oSel = document.selection.createRange(); 
                oSel.moveStart('character',this.value.length); 
                oSel.moveEnd('character',0); 
                oSel.select(); 
            } 
        }
})

See more: http://forum.jquery.com/topic/ui-autocomplete-multiple-demo-caret-position-in-ie http://jqueryui.com/demos/autocomplete/#multiple

Aaron Harun
Thanks for the suggestion Aaron, I didnt find that answer in any of my googling. However I cant see how to implement this fix. I have searched for the non-minified versions of jquery ui core, autocomplete and the jquery library itself and cant find the line 'this.value = terms.join(", ");' anywhere. I dont know if this fix relates to an old version though the post is less than a month old. Very strange. Any other ideas?RegardsSteve
CountZero
Oh that was specific to the multiple version of the autocomplete. It was supposed to be added in the select event of the .autocomplete code. I'll edit what I found into the post.
Aaron Harun
Thanks Aaron, working beautifully. Just knew even after spending a couple of days updating our platform to support autocomplete the first thing the client would do is moan about this glitch. Cheers!
CountZero
No problem, it always surprises me what clients will sometimes complain about first. Sometimes they will ignore what looks like a giant pink elephant to us, to point out a speck of dirt. **shrug**
Aaron Harun