Jquery UI Autocomplete doesn't allow options to be selected with mouse anymore
Asked Answered
S

3

5

I recently updated jquery ui and its autocomplete plugin - however in the newer version it won't let me select the options with a mouse click and I have to use the up and down arrows. How do I re-enable selection via mouse click?

Btw the new version is 1.9.1, old version was 1.8.2

Selfconfessed answered 14/11, 2012 at 13:9 Comment(3)
you can still select via the mouse in UI 1.9.1. Try using the example here: jqueryui.com/autocomplete Can you post some code?Lasso
Hi Elliott - the demo is working correctly, but on the two pages where I'm using the plugin I can't select with the mouse at all. Must be a conflict somewhere. If I get a chance I'll look into whats causing it and submit as a bugSelfconfessed
I downgraded to the previous version in the end.Selfconfessed
M
4

In my case the mouse selection capability was disabled by an outdated third party jQuery plugin. This thread gave me an idea of what might be wrong: http://forum.jquery.com/topic/autocomplete-click-to-select-item-not-working-in-1-9-1

I was using an old version of jquery validation plugin (https://github.com/jzaefferer/jquery-validation). I disabled one plugin after another to see which was causing the misbehaviour.

Mohun answered 24/1, 2013 at 9:17 Comment(3)
Thanks bubblez, that fixed it for me, you've saved me hours :)Daveen
For me it turned out to be a call to stopPropagation() on a click in body e.g. $("body").click(function (e) {e.stopPropagation()}; look for code like this and comment out stopPropagation().Lefthanded
Thanks,That fixed it 👍Muezzin
C
2

I had the same issue, even using the latest version of jquery-ui available at the time 1.11.4

Checking the source code in file jquery-ui.js I found a piece like this:

"click .ui-menu-item": function( event ) {
                    var target = $( event.target );
                    if ( !this.mouseHandled && target.not( ".ui-state-disabled" ).length ) {
                        this.select( event );

                        // Only set the mouseHandled flag if the event will bubble, see #9469.
                        if ( !event.isPropagationStopped() ) {
                            this.mouseHandled = true;
                        }

The problem is the mouseHandled var set to true. But it only happens if the event propagation hasn't been stopped.

So as the solution I defined my autocomplete like this:

$('.autocomplete').autocomplete({
  source: ['value1','value2','value3','value4'], //my source
  select: function(event, ui){
    event.stopPropagation(); //the select event will work next time you click
    //your logic comes here ...
  }
})

It worked for me, I hope it works for you! =)

Cryptography answered 1/12, 2015 at 12:59 Comment(0)
V
0

The most recent version has fixed this.

Just update to the latest version of jquery.validate.js from http://jqueryvalidation.org/. For example download Microsoft’s Ajax CDN (hotlinking welcome) http://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/jquery.validate.js

Valiancy answered 26/11, 2014 at 21:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.