Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nesting optgroups in a dropdownlist/select

Tags:

html

optgroup

I have created a customer c# DropDownList control that can render out it's contents are optgroups (Not from scratch, I edited some code found on the internet, although I do understand exactly what it's doing), and it works fine.

However, I have now come across a situation where I need to have two levels of indentation in my dropdown, i.e.

<select>    <optgroup label="Level One">      <option> A.1 </option>      <optgroup label="Level Two">        <option> A.B.1 </option>      </optgroup>      <option> A.2 </option>    </optgroup>  </select>

However, in the example snippet above, it is rendering as if Level Two was at the same amount of indentation as Level One.

Is there a way to produce the nested optgroup behavior I am looking for?

like image 785
Ed James Avatar asked Jun 24 '09 11:06

Ed James


People also ask

How do you define a group of related options in a drop-down list?

We can define a group of related options in a drop-down list by using the <optgroup> Tag tag is used to create a group of same category options in a drop-down list. The tag is required when there is a long list of items.

Which tag is used to group Dropdownlist options?

Definition and Usage The <optgroup> tag is used to group related options in a <select> element (drop-down list).

Which element allows for the creation of groups of options in a select menu?

The <optgroup> HTML element creates a grouping of options within a <select> element.


1 Answers

The HTML spec here is really broken. It should allow nested optgroups and recommend user agents render them as nested menus. Instead, only one optgroup level is allowed. However, they do have to say the following on the subject:

Note. Implementors are advised that future versions of HTML may extend the grouping mechanism to allow for nested groups (i.e., OPTGROUP elements may nest). This will allow authors to represent a richer hierarchy of choices.

And user agents could start using submenus to render optgoups instead of displaying titles before the first option element in an optgroup as they do now.

like image 103
Raphael Schweikert Avatar answered Oct 02 '22 07:10

Raphael Schweikert