Re: [VE] [html5] spurious "must have child option" when all options in optgroups

Thanks for the clarification, Yucca.

I guess I have a problem with the spec. I believe that if my select is 
required and I have an option selected, then I should not need a 
placeholder. From what I've read, the following situation would be 
legitimate in HTML 4.01 but not in HTML 5.

<!DOCTYPE html>
<title>test</title>
<select size=1 required>
<optgroup label=jkldf>
     <option selected>hello
</optgroup>
</select>

I can work around this by adding a placeholder option with 
style="display: none", but that smells bad.


Ken

On 04/16/2014 10:25 AM, Jukka K. Korpela wrote:
> 2014-04-16 17:25, Philip Taylor wrote:
>
>> (a) We should point out to Mr Geis that reading the HTML 4.01
>> specification is not always useful when deciding what is or
>> is not valid in HTML 5,
>
> Or, more exactly, that HTML 4.01 as such is irrelevant in that 
> respect. There is no exact definition of exactly what HTML5 validation 
> checks against, but it’s presumably either HTML5 CR or HTML 5.1 
> Nightly or something between them, as interpreted and modified by the 
> authors of the validator.
>
>> (b) Mr Geis specifically quoted "A select element with a /required/
>> attribute a ...", and this example, which meets that constraint, does
>> indeed fail as he asserts :
>>
>> <!DOCTYPE html>
>> <title>test</title>
>> <select size=1 required>
>> <optgroup label=jkldf>
>>     <option>hello
>> </optgroup>
>> </select>
>
> That is correct, in two ways. It indeed fails, and failing validation 
> is consistent with HTML5 CR, which says:
>
> "If a select element has a required attribute specified, does not have 
> a multiple attribute specified, and has a display size of 1; and if 
> the value of the first option element in the select element's list of 
> options (if any) is the empty string, and that option element's parent 
> node is the select element (and not an optgroup element), then that 
> option is the select element's placeholder label option.
>
> If a select element has a required attribute specified, does not have 
> a multiple attribute specified, and has a display size of 1, then the 
> select element must have a placeholder label option."
>   http://www.w3.org/TR/html5/forms.html#the-select-element
>
> It sounds complicated, and it is almost as complicated as it sounds. 
> But reading backwards, the rules here say that in the given case, the 
> <select> element must have a "placeholder label option", which means 
> an <option> element that either has value="" or has no value attribute 
> and no text content - a dummy option indeed. Moreover, the <option> 
> element must be the first child of the <select> element, for example
>
> <select size=1 required>
> <option value="">Please select the greeting:
> <optgroup label=jkldf>
>    <option>hello
> </optgroup>
> </select>
>
> This requirement has a fairly complex history. But the point is that 
> it is in the HTML5 CR, so the error message "A select element with a 
> required attribute and without a multiple attribute, and whose size is 
> 1, must have a child option element" is adequate (though not ideal 
> perhaps in its formulation).
>
> Yucca
>

Received on Wednesday, 16 April 2014 18:00:51 UTC