Prevent auto select first option of multiselect box in iPhone Safari - html

I have a problem with multiselect box on iPhone Safari. When I open the multiselect box it automatically selects the first option. Here is the code snippet that i am using:
<select multiple>
<option value="test1">Test 1</option>
<option value="test2">Test 2</option>
<option value="test3">Test 3</option>
</select>
I have added a blank option with the disabled attribute (see below from here) as the first option but it didn't work in iPhone Safari. I am using an iPhone 6s+:
<option disabled></option>

disable=disable
just add it in option so that no one will be able to access that option

<option selected=selected value="test0">Pick an option</option>
Use the attribute selected to specify that this option should be the one selected. Or put the first one you want to see selected by default at the top of your list.
disabled attribute will, well i know how unprobable it sounds, disable your select option, thus means it will not be able to be selected.

Related

Buggy multi-select element on iPhone 5S with iOS 7

I'm testing a multi-select box on iPhone 5S iOS 7 -- on Browserstack's "real devices" -- but it seems buggy and wanted to know if this is a known issue, and if there's a workaround.
Buggy behaviour 1 Safari removes the last option a user has selected after choosing done, moving to the next > input field (if there is one), or hitting a submit button (if there is one).
<select multiple="multiple">
<option value="Saxophone">Saxophone</option>
<option value="Flute">Flute</option>
<option value="Clarinet">Clarinet</option>
</selct>
So, before making any selections the dropdown menu displays "0 Items"; if you were to select Saxophone from the above list, it would display "Saxophone", but then when you hit Done Saxophone is deselected and it displays "0 Items" again. If you were to select Saxophone then Flute, it would display "2 Items", but then when you hit Done it would deselect Flute and display only "Saxophone". And just for the FUN of all this, if you were to select Saxophone, Flute and lastly Clarinet, then hit Done, it would deselect Clarinet and display "2 Items".
Note: This occurs with or without the optgroup's as described below.
Buggy behaviour 2: Safari crashes when using an optgroup when the select box is selected. A workaround I've found is placing a disabled option before the first optgroup.
So, this crashes:
<select multiple="multiple">
<optgroup label="Private">
<option value="Saxophone">Saxophone</option>
<option value="Flute">Flute</option>
<option value="Clarinet">Clarinet</option>
</optgroup>
</selct>
But this doesn't:
<select multiple="multiple">
<option disabled value="choose"></option>
<optgroup label="Private">
<option value="Saxophone">Saxophone</option>
<option value="Flute">Flute</option>
<option value="Clarinet">Clarinet</option>
</optgroup>
</selct>
I'm also wondering if anybody has seen this on other iOS versions/devices.
Thanks!

Mobile Safari multi select bug

If found a really annoying bug on the current (iOS 9.2) mobile safari (first appearing since iOS 7!)
If you using multi select fields on mobile safari - like this:
<select multiple>
<option value="test1">Test 1</option>
<option value="test2">Test 2</option>
<option value="test3">Test 3</option>
</select>
You will have problems with automatically selection!
iOS is automatically selecting the first option after you opened the select (without any user interaction) - but it will not show it to you with the blue select "check".
So if you now select the second option, the select will tell you that two options are selected (but only highlighting one as selected)...
If you now close and open the select again, iOS will automatically deselect the first value - if you repeat, it will be selected again without any user interaction.
Thats a really annoying system bug, which is breaking the user experience!
Solution for safari multi select bug and Empty and Disabled option tick related issue:
<select multiple>
<optgroup disabled hidden></optgroup>
<option value="0">All</option>
<option value="1">Test 1</option>
<option value="2">Test 2</option>
<option value="3">Test 3</option>
<option value="4">Test 4</option>
</select>
Add a disabled and hidden optgroup before the real options.
After a long research I found the following (not most beautiful) but working solution:
The trick is to add a empty and disabled select option at the fist position:
<select multiple>
<option disabled></option>
<option value="test1">Test 1</option>
<option value="test2">Test 2</option>
<option value="test3">Test 3</option>
</select>
This will prevent iOS from automatically selecting the first option and keep the selection values right and clean!
The empty option is not visible and the count of the selections is correct.

use css to resize select tag in form to see all option tags

Is it possible to dynamicaly resize the visible options in select tag in forms? I have the example:
<select size="1">
<option value='1'>1
<option selected value='2'>2
<option value='3'>3
<option value='4'>4
</select>
I would like to have visible all options (to setup size dynamically with css) when design page for printing. And also to see selected option(s) in another design (color, bold ...). For resize I tried:
select{
size:4;
}
but it doesn't work. I need a working solution at least for FF, IE, Safari ...
Do have any idea?
Thanks in advance!
You can use this way:
<select size="1" size="4">
<option value='1'>1</option>
<option selected value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
</select>​​​​​​​​​​​​
And don't forget to close the </option>

Does Native HTML have a ListBox element

Does native HTML have a listbox element? You know how it has a drop box element (called select), does it also have a listbox?
If not, do you know how I could place a list box in my Website.
One method, is to create a table & have each element detect the onclick event. But I dont want to make my own just yet. Are javascript widgets easy to use?
Use a select list:
<select multiple="multiple" size="2">
<option value="Whatever">One</option>
<option value="Other">Two</option>
</select>
#Myles has the select box which is correct, you can also allow multiple select options.
<select multiple="multiple">
<option value="opt1">Option 1</option>
<option value="opt2">Option 2</option>
<option value="opt3">Option 3</option>
</select>
Add the multiple attribute to a normal <select> and use the size attribute to determine how many rows you want shown. (If you don't set the size attribute, then all options will be visible.):
<select multiple="multiple" size="5">
See example.
I think what you need is the select tag, but set the selects attributes of multiple and size. Here is a reference http://www.w3schools.com/tags/tag_select.asp.
<select multiple='multiple' size='3'>
<option value='o1'>Red</option>
<option value='o2'>Green</option>
<option value='o3'>Blue</option>
</select>
At this moment the standards do not have a listbox element.
There's a web spec in progress about the <selectmenu> element which does have a listbox slot (not element). Possibly this could end up being back in the <select> element
If you want to read more about it:
https://open-ui.org/prototypes/selectmenu
https://css-tricks.com/the-selectmenu-element/

DropDownList with Firefox and ASP.NET MVC

I have been hitting a brick wall on this for about an hour now. I have a list of counties that I build and add to my view data (counties) and then render the list with a: html.DropDownList('invoice.county', counties) in my view.
It appears to render correctly but FF REFUSES to set the selected item. I have tried swapping the values out for integers (so they don't match the display text) and that did not work. FF just displays the first item in the list
<select id="invoice_county" name="invoice.county">
...
<option value="Lander">Lander</option>
<option selected="selected" value="Laramie">Laramie</option>
<option value="Larimer">Larimer</option>
...
</select>
I have trimmed the values to the ones surrounding the selected item.
Can anyone give me insight into this????
Firefox has a weird bug/feature that means if you just refresh the page, it will select the option already selected regardless of whether the selected attribute is on another option. For example, if I put in:
<select id="invoice_county" name="invoice.county">
<option value="Lander">Lander</option>
<option selected="selected" value="Laramie">Laramie</option>
<option value="Larimer">Larimer</option>
</select>
Saved and refreshed in Firefox, then put:
<select id="invoice_county" name="invoice.county">
<option selected="selected" value="Lander">Lander</option>
<option value="Laramie">Laramie</option>
<option value="Larimer">Larimer</option>
</select>
instead and just refreshed after saving, it would keep "Laramie" selected. To stop this, try Ctrl-F5 rather than just F5 or refresh.
If you are using XHTML, you need a valid attribute/value pair:
<option selected="selected" value="x">
If you are using HTML, the mere presence of the attribute is enough:
<option selected value="x">
More information on W3C.