[whatwg] The legend element

Markus Ernst derernst at gmx.ch
Mon Oct 12 03:59:09 PDT 2009


Ian Hickson schrieb:
> 
>> Additionnally I want to suggest to make it possible to place the legend 
>> element outside the fieldset element, providing a "for" attribute (just 
>> as it is possible to place the label element apart from it's form field 
>> element).
> 
> This is significantly harder to pull off, for the same reason that we 
> haven't been able to use <legend> for <figure>. I recommend we wait for 
> the next version of HTML before doing this.

Would it be possible and easy to allow <label> for fieldsets? This looks 
somehow consistent to me:

<h2><label for="question1">Favorite pet?</label><h2>
<fieldset id="question1">
   <p><label><input type="radio" name="q1" value="Cat">Cat</label></p>
   <p><label><input type="radio" name="q1" value="Dog">Dog</label></p>
   <p><label><input type="radio" name="q1" value="Ant">Ant</label></p>
</fieldset>

or:

<label>
   <h2>Favorite pet?<h2>
   <fieldset>
     <p><label><input type="radio" name="q1" value="Cat">Cat</label></p>
     <p><label><input type="radio" name="q1" value="Dog">Dog</label></p>
     <p><label><input type="radio" name="q1" value="Ant">Ant</label></p>
   </fieldset>
</label>

>> Background: When writing template based applications, it can be useful 
>> to provide a placeholder for the whole fieldset, and another one for the 
>> legend, as template authors might want to place or style them 
>> individually.
>>
>> Example - a questionnaire:
>>
>> Template Variable {question} outputs:
>> <legend for="question1">What ist your favorite Pet?</legend>
>>
>> Template Variable {answers} outputs:
>> <fieldset id="question1">
>>   <p><label><input type="radio" name="q1" value="Cat">Cat</label></p>
>>   <p><label><input type="radio" name="q1" value="Dog">Dog</label></p>
>>   <p><label><input type="radio" name="q1" value="Ant">Ant</label></p>
>> </fieldset>
>>
>> One author might want to use this template:
>> <h2>{question}</h2>
>> {answers}
>>
>> The other one prefers:
>> <table>
>>   <tr>
>>     <td>{question}</td>
>>     <td>{answers}</td>
>>   </tr>
>> </td>
>>
>> While the desired results can be easily achieved with the current legend 
>> specification when coding manually, it is quite hard to implement with a 
>> template system, needing separate template variables for both the 
>> fieldset start and end tags, and a loop for the questions. With the 
>> focus of making an application as easy to use as possible (which 
>> includes template authoring), application authors might rather go 
>> without fieldset and legend, and accept the loss of structural 
>> consistency and accessibility as a trade-off.
>>
>> I am sure this change would not break legacy content in new browsers; 
>> anyway I have no Idea how far it would break HTML5 content in legacy 
>> browsers.
> 
> I don't understand why the <fieldset> and <legend> can't be in the 
> template.

That is how I do it now. The downside of it is the fact that some 
themplate authors might forget it - a relevant number of web designers 
in fact don't even know about fieldsets, as forms usually "work" with or 
without them. Anyway it is not a big problem; it would just be a nice 
enhancement of consistency if the template engine were able to output 
*all* form structuring elements.



More information about the whatwg mailing list