select2 icon indicating copy to clipboard operation
select2 copied to clipboard

Selecting Select2 box on iPad causes scroll event, can't then click on the Select2 box.

Open johnavance opened this issue 14 years ago • 18 comments

On Safari iPad 3, tapping on a select2 box when the page is scrolled down, causes the page to scroll to the top. Attempting to access the opened select2 box causes it to close. Poof! It's gone.

johnavance avatar Sep 18 '12 17:09 johnavance

Tested and confirmed on Select2 version 3.2 on iPad 1 and 2 under iOS 4.3.3 and on iPad 2 under iOS 5.1.1. (incidentally also on iPhone 4s - although not a target) Preliminary testing using Select2 version 2.1 indicates better behaviour (although 2.1 has issues with ie7). I'll do some more testing and confirm the regression. This ties in with some of the usability issues mentioned in Issue #312 (https://github.com/ivaynberg/select2/issues/312)

lukebrowell avatar Sep 18 '12 21:09 lukebrowell

This has to do with the href portion of the container being "#". The event used to be stopped in initContainer, but that was removed with Select2 3.0.

kevin-brown avatar Sep 18 '12 22:09 kevin-brown

Interesting, my money was on fn-positionDropdown relying on scrollTo (and the interesting way in which Mobile Safari handles it), although I'm relatively new to Select2. The href hash issue makes sense: Can you recommend a patch?

lukebrowell avatar Sep 18 '12 22:09 lukebrowell

The issue was introduced in 84eb5b33fc2d9b514a87effacc93968699095787, where killEvent(e); was removed from the click handler.

Not sure why that was removed, it looks like it could be added back without any conflicts. It's also a temporary fix at the moment.

kevin-brown avatar Sep 18 '12 22:09 kevin-brown

Thanks Kevin, i'll test it out and report back. When I diff'd 2.x against the master branch I also noticed the addition of mouseMove events for tracking last position - I can't imagine them working too well in a touch environment. What's the current approach for handling touch vs mouse events?

lukebrowell avatar Sep 18 '12 22:09 lukebrowell

I couldn't get this to work and it needed to go live, so I just worked around it for the time being by selectively binding to the unwanted event and preventing it from bubbling. Neither big nor clever, but it works until I can find something better.

lukebrowell avatar Oct 02 '12 21:10 lukebrowell

I confirm this issue : select2's examples are unusable on an ipad 2

namlook avatar Oct 10 '12 14:10 namlook

(update - previous workaround broke in chrome)

If you add event.preventDefault() immediately before return false; to all of the onclick handlers created by select2, this seems to resolve the ipad issues.

See here for more: http://stackoverflow.com/questions/10152577/a-href-onclick-return-false-not-working-in-safari-ios

tyschroed avatar Oct 18 '12 19:10 tyschroed

This was fixed in #487.

kevin-brown avatar Oct 24 '12 00:10 kevin-brown

I can confirm this issue still exists on an iPad 2 running iOS 6 using 4a363c4b30 . Kevin's mentioned fix and pull request don't work for me. The weird thing for me is that it works in landscape but not portrait. I'll post back if I find anything else out

KeithMcPherson avatar Oct 28 '12 22:10 KeithMcPherson

Come to find out this was completely unrelated to the pull request.

This should be able to be fixed by killing the click event completely. Also, it happens on the iPhone (iOS 6) in both portrait and landscape.

kevin-brown avatar Oct 28 '12 22:10 kevin-brown

Do you mean the onClicks in the generated a tags? Still no dice. Also, not sure if I need to make a new bug report for this since it's likely related, but if I have a search drop down, I can get the keyboard to open on an iPad, but as soon as I hit a letter, it does the same thing as the other drop downs.

KeithMcPherson avatar Oct 28 '12 22:10 KeithMcPherson

You would need to add

killEvent(e);

at line 1540.

If this works, feel free to make a pull request with the change.

kevin-brown avatar Oct 28 '12 22:10 kevin-brown

Well, after much more poking around this week, I've not made any real progress. Trying various killEvents in different spots did not work, apart from breaking functionality and introducing some more interesting glitches. I think that it's not just specific to the click events, but also to the keyup and keydowns as well. I think someone with a better understanding of javascript/iOS will have more luck, since I'm relatively new to both. I know it's not a solution to this bug, but I ended up just using jqueryui's autocomplete to accomplish what I needed on an iPad.

KeithMcPherson avatar Nov 03 '12 23:11 KeithMcPherson

The easiest fix would be changing

.. onclick="return false;" ..

to

.. onclick="event.preventDefault(); return false;" ..

That helped me fix the issue with mobile safari.

madhenry avatar Nov 18 '12 21:11 madhenry

madhenry's above post is also the quick fix for me on devices under iOS 5

Not a issue though on iPad 2 under iOS 6

athanph avatar Dec 12 '12 13:12 athanph

This was a problem for me on iOS 6.0.1 and iPhone 5. Chosen did not seem to have this problem. I used the online demo at http://ivaynberg.github.com/select2/

fingermark avatar Dec 18 '12 00:12 fingermark

fixed in #669

ivaynberg avatar Jan 31 '13 05:01 ivaynberg