[whatwg] optgroup element used for selection

Markus Ernst schrieb:
> Randy Drielinger schrieb:
>> Currently (HTML4.01) and in the near-future HTML5 spec optgroup 
>> elements are used to group options (hence the name :-) and amongst 
>> others allow us to disable a group of option elements at once.
>>  
>> Personally, I think it would make sense to add the ability to make an 
>> optgroup selectable. The result *could* be to select all the childs of 
>> that optgroup element (or simply post the child values as an array or 
>> whatever).
>>  
>> I've searched through the archive and only found discussions regarding 
>> nested optgroups.
>>  
>>  
>> In a form submission case it would make sense as optgroups are used to 
>> subcategorize options. If optgroups are used in for example search 
>> pages on websites, it would allow users to only select an optgroup to 
>> select all of it's childs in, as an example, the following scenario:
>>  
>> <select>
>>  <optgroup label="Excel">
>>    <option label="Excel 2000">Excel 2000</option>
>>    <option label="Excel 2002">Excel 2002</option>
>>    <option label="Excel 2003">Excel 2003</option>
>>    <option label="Excel 2007">Excel 2007</option>
>>  </optgroup>
>>  <optgroup label="Word">
>>    <option label="Word 2000">Word 2000</option>
>>    <option label="Word 2002">Word 2002</option>
>>    <option label="Word 2003">Word 2003</option>
>>    <option label="Word 2007">Word 2007</option>
>>  </optgroup>
>> </select>
>>  
>> Would all of the above make sense? Or don't y'all encounter issues 
>> related to form usability at the moment?
> 
> The idea looks good to me, while I am not familiar with possible earlier 
> discussion of it. Anyway this behaviour should be restricted to select 
> elements with a "multiple" attribute, where multiple selections are 
> allowed at all.
> 
> 
It might even be useful to allow a value attribute to the optgroup element:
- Optgroup selected, no value attribute provided: Submit array of child 
option values
- Optgroup selected, value attribute provided: Submit value of optgroup 
element

A possible use case for this - the assignment of pictures to a gallery 
page in a CMS:

<select name="pix[]" multiple>
   <optgroup label="My family" value="family">
     <option value="mom.jpg">Mom</option>
     <option value="pa.jpg">Pa</option>
   </optgroup>
   <optgroup label="My pets" value="pets">
     <option value="cat.jpg">Cat</option>
     <option value="dog.jpg">Dog</option>
   </optgroup>
</select>

Like this you can assign either single pictures or whole categories 
(including future entries to the categories, as you submit the category 
name rather than the contents). Currently the solution for the same task 
looks somehow like this:

<select name="pix[]" multiple>
   <option value="family">My family</option>
   <option value="mom.jpg">&nbsp;&nbsp;Mom</option>
   <option value="pa.jpg">&nbsp;&nbsp;Pa</option>
   <option value="pets">My pets</option>
   <option value="cat.jpg">&nbsp;&nbsp;Cat</option>
   <option value="dog.jpg">&nbsp;&nbsp;Dog</option>
</select>

Which does actually work, but is not structurally nice.

Received on Monday, 13 April 2009 05:56:41 UTC