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

前端 未结 12 1193
野趣味
野趣味 2020-12-01 02:41

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

12条回答
  •  我在风中等你
    2020-12-01 03:23

    Wrote a super nasty hack which seems to do the trick for me. Here's what I did.

    1. Check that we're using a touch device (in my case, a variable I have called IAmTouchy.
    2. Listen for a tap (touchstart) on an autocomplete result.
    3. After a set time, check to see if the autocomplete results are still visible. If they are, and an item is focussed, trigger a click on it.
    4. (optional) Try once more... in case the set time wasn't long enough for the element to gain the ui-state-focus class.

          $('.autocompleteContainer').on('touchstart', 'li.ui-menu-item', function(){
      
              var $container = $(this).closest('.autocompleteContainer'),
                  $item = $(this);
      
              //if we haven't closed the result box like we should have, simulate a click on the element they tapped on.
              function fixitifitneedsit() {
                  if ($container.is(':visible') && $item.hasClass('ui-state-focus')) {
      
                      $item.trigger('click');
                      return true; // it needed it
                  }
                  return false; // it didn't
              }
      
              setTimeout(function () {
                  if (!fixitifitneedsit()) {
                      setTimeout(fixitifitneedsit, 600);
                  }
              }, 600);
          });
      

    Hopefully someone has a nicer solution though!

提交回复
热议问题