Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autocomplete requires you to click twice in iOS after update to 1.11.0

Using jQuery 2.1.0 and jQuery.ui 1.11.0 Tested in iOS 7. iPhone and iPad Mini. Works on android and regular browsers.

The problem

We recently upgraded from jQuery UI 1.10.0 to 1.11.0 and now, when clicking an item in an autocomplete results list, you only get a hover, you have to click the same element again to get a click event. This used to work fine with version 1.10.0.

(JSFiddle link in comments)

What does not work

using css {cursor: pointer} does not work

using onclick="" does not work

(JSFiddle link in comments)

The weird part

But here comes the fun/weird part. It works in JSFiddle edit view, but not on the JSFiddle "/show" page.

JSFiddles: (type a letter to show results "s" is a good one)

  • Html view (does not work)

  • Edit view (works)

I've been working on this for days, but hadn't been able to reproduce it in JSFiddle before testing only the html view. So now I turn to you. I can't for the life of me figure out why the one page triggers a click event, and the other does not.

I am using the most basic function of jQuery autocomplete. In fact, using the exact same code that is presented on jQuery UI's home page.

The question

So, how do I get autocomplete to work with one click in iOS on the /show page?

(I will post additional links in comments because I don't have 10 rep yet. Unless I don't have enough rep to comment...)

like image 560
Snorre Kim Avatar asked Aug 13 '14 12:08

Snorre Kim


3 Answers

Just a bit later, but

$("#input").autocomplete({
    open: function(event, ui) {
        $('.ui-autocomplete').off('menufocus hover mouseover mouseenter');
    }
});
like image 163
onlydimon Avatar answered Sep 23 '22 14:09

onlydimon


For some strange reason @onlydimon's answer didn't work for me. It seems like we do need event mouseenter. Following answer worked well for me.

open: function (result) {

            if (navigator.userAgent.match(/(iPod|iPhone|iPad)/)) {
                $('.ui-autocomplete').off('menufocus hover mouseover');
            }
        },

I have added a condition to make sure that it doesn't break in other devices.

like image 32
Sangram Nandkhile Avatar answered Sep 21 '22 14:09

Sangram Nandkhile


Building on onlydimon’s solution:

var input = $("#input")
// Initialize autocomplete
input.autocomplete()
// Retrieve the autocomplete list and remove the mouseenter event
// which seems to trip up iOS Safari
input.autocomplete('widget').off('mouseenter')

I narrowed down the list of events to just jQuery's 'mouseenter' event. Removing just this one fixes the bug for me. Also, no need to remove it every time the list is opened; once is enough.

like image 34
fvsch Avatar answered Sep 19 '22 14:09

fvsch