CountZero
CountZero

Reputation: 6389

jQuery UI Autocomplete IE Cursor Position Bug

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

Upvotes: 0

Views: 3077

Answers (2)

human.js
human.js

Reputation: 1382

http://bugs.jqueryui.com/ticket/6858 This one helped me a lot!

Upvotes: 1

Aaron Butacov
Aaron Butacov

Reputation: 34347

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

Upvotes: 1

Related Questions