Multiple Select on Safari - iPhone iOS 7

It appears the multiple select element is broken for the iPhone on iOS 7 in Safari and Chrome. (http://jsfiddle.net/ryborg/UjJ87/)


When the user expands the option list and clicks the Done cta to collapse the option list, the browser does some weird stuff.


  1. If no option is selected, it selects the first option in the list.
  2. If one option is selected, it deselects that option.
  3. If multiple options are selected, it deselects the last option to be tapped.
  4. If an option previously selected is deselected, it reselects the option.


Looking at the iPhone console from Safari 6 on my Mac shows that a change event fires for the select element when the option list is opened and again when it is closed. The desktop browsers are only firing change events when the options are (de)selected.


This is not happening on iPhone 3GS running iOS 6 nor on iPad 2 or iPad Mini running iOS 7.


Can anyone else reproduce this issue? Any suggestions on how to solve it?

iPhone 5, iOS 7.0.3

Posted on Nov 11, 2013 7:46 AM

Reply
20 replies

Nov 25, 2013 2:35 AM in response to ryborg

It's a nasty work around but it solved the weird event handling for me.


Example in jQuery:


var doChange = false;

$('select').on('focusin change focusout', function(e){


switch(e.type){

case 'focusin':

doChange = true;

break;

case 'change':


if(!doChange){

return false;

}


break;

case 'focusout':

doChange = false;

break;

}


if(e.type == 'change'){

// do your onchange stuff

}

});

Dec 6, 2013 1:14 PM in response to kjfranke

This workaround seems to fix some of the eveny craziness with the SELECT tag, but it doesn't seem to prevent the tag from doing the "after close" unselection of the last tapped item. In a nutshell the select tag is a pretty severely broken in iOS 7 Safari for iPhone/iPod, and that bug that renders multiple selection dropdowns pretty much useless. Someone at Apple got too mesmerized by their new shiny "scrolling wheel" selection meme, and then never actually did any actual testing on it. Does anyone know the ID of the submitted bug to Apple on this one?

Jan 2, 2014 2:52 AM in response to half-star

There appears to be a solution, its ugly, but it seems to work.


The sequence of events for a multiselect (at least in the simulator) are as follows:-


CHANGE

...

CHANGE

BLUR

CHANGE


Its the final CHANGE event which does the damage.


The solution is to set a flag in the BLUR event, so the final CHANGE is discarded. Record the full set of selected options for each CHANGE event, but on the CHANGE event after the BLUR, reinstate the value recorded by the previous CHANGE event.


The reinstatement has to be via setTimeout(100 milliseconds seems about right) - setting the value straight away is ignored.


This solution has NOT been extensively tested, so far I've only tried it in the simulator. In addition it is likely to be unstable - when Apple fixes the bug, this solution will almost certainly break.


A safer solution would be to replace the multiselects with a custom div based solution - but this looks ugly.

Jan 29, 2014 11:26 PM in response to ryborg

All current solutions were not good enough to fit my needs. The general idea of all offered solutions is to reselect values after closing select. But when you open select again - selected items will be incorrect.


In my project all selected items should remain selected after closing/opening selectbox. Solution is to add fake first option with "Select Options" label, that should not be able to select, and restore selected options after closing select options.


// hack for iPhone 7.0.3 multiselects bug if(navigator.userAgent.match(/iPhone/i)) { $('select[multiple]').each(function(){ var select = $(this).on({ "focusout": function(){ var values = select.val() || []; setTimeout(function(){ select.val(values.length ? values : ['']).change(); }, 1000); } }); var firstOption = '<option value="" disabled="disabled"'; firstOption += (select.val() || []).length > 0 ? '' : ' selected="selected"'; firstOption += '>« Select ' + (select.attr('title') || 'Options') + ' »'; firstOption += '</option>'; select.prepend(firstOption); }); }

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Multiple Select on Safari - iPhone iOS 7

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.