Selecting Select2 box on iPad causes scroll event, can't then click on the Select2 box.
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.
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)
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.
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?
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.
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?
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.
I confirm this issue : select2's examples are unusable on an ipad 2
(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
This was fixed in #487.
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
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.
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.
You would need to add
killEvent(e);
at line 1540.
If this works, feel free to make a pull request with the change.
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.
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'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
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/
fixed in #669