[whatwg] default select item that does not satisfy required attr.

from the web forms doc in the comment at the bottom:

   * have a way of marking the first option of a <select> as the default
     but have it not satisfy a new required="" attribute on <select> so
     that you can have selects that require a valid value.



my proposed solution:

1. if select is flagged as "required" then the default option does not 
satisfy the required status.

<select required>
<option default>PLEASE SELECT A STATE
<option value="--">Non-US
<option value="AL">Alaska
</select>



2. if no item is flagged as "selected" then it is selected, but it need 
not be the top of the list:

<select name="timezone">
<option>GMT - 2
<option>GMT - 1
<option default>GMT
<option>GMT + 1
<option>GMT + 2
</select>

straight away I've broken my own solution, as "GMT" is a valid timezone, 
so if the timezone select had a "required" flag then the UA would not 
allow it. however in this instance there is no psudeo "select timezone" 
option, so as long as one option is selected (and in a drop-down single 
select box this is always the case) then it will always be valid.


however i've thought of another case, with a formatted list:

<select required>
<option default>PLEASE SELECT A MAIN COURSE
<option>--- PIES ---
<option>steak
<option>chicken
<option>veggie
<option>--- OTHER ---
<option>pizza
<option>fish and chips
</select>

here the first, second and 6th options are invalid so need to not 
satisfy the required flag, one solution is to have optgroups:

<select required>
<option default>PLEASE SELECT A MAIN COURSE
<optgroup> --- PIES ---
	<option>steak</option>
	<option>chicken</option>
	<option>veggie</option>
</optgroup>
<optgroup> --- OTHER ---
	<option>pizza</option>
	<option>fish and chips</option>
</optgroup>
</select>

which could be nested:

<select required>
<option default>PLEASE SELECT A MEAL
<optgroup> --- MAIN COURSE
	<optgroup> --- PIES ---
		<option>steak</option>
		<option>chicken</option>
		<option>veggie</option>
	</optgroup>
	<optgroup> --- OTHER ---
		<option>pizza</option>
		<option>fish and chips</option>
	</optgroup>
</optgroup>
</select>

interestingly the optgroup may also be used to solve this problem:

  * A fairly common situation for web authors is to have two lists, where
    the contents of the second depends on the value of the first. Is here
    any way we could extend the current model to include this functionality?

by having each optgroup in the second select married to the selected 
value of the first, and indeed a third select could have (very many) 
optgroups which switch depending on the value of the third by hooking 
them in a way similar to the data list. Though exactly how would be a 
seperate discussion



ric hardacre
http://www.cyclomedia.co.uk/
http://www.ricster.me.uk/

Received on Friday, 24 February 2006 01:25:20 UTC