Re: Datalist - option error

7/27/2015, 4:21 PM, benoit.poirot@free.fr wrote:

> *Error*:Element|option|without attribute|label|must not be empty.

This error message directly reflects a requirement on the <option> 
element in the W3C HTML5 REC. According to it, the content model (i.e. 
rules for allowed and required content) says:

Content model:
If the element has a label attribute and a value attribute: Empty.
If the element has a label attribute but no value attribute: Text.
If the element has no label attribute: Text that is not inter-element 
whitespace.

http://www.w3.org/TR/html5/forms.html#the-option-element

So when you have

> <option value="RdC">

the third alternative above applies, and it says that the element must 
gave some non-blank content. But your document contains a sequence of 
<option> tags, with just line breaks and maybe spaces between, making 
the content consist of “inter-element whitespace” only.

However, the W3C HTML5 REC itself contains the following example of a 
<datalist> element:

<label>
  Sex:
  <input name=sex list=sexes>
  <datalist id=sexes>
   <option value="Female">
   <option value="Male">
  </datalist>
</label>

which causes the same error message. So there is an inconsistency in the 
specification, and the validator happens to apply the rules under 
“Content model”.

The obvious way to make the code validate, considering the context of a 
<datalist> element, is to duplicate the information, e.g.

<option value="RdC" label="RdC">

Maybe the authors of the specification really meant this, and maybe the 
example not using the label attribute is a holdover from earlier drafts.

Yucca

Received on Thursday, 30 July 2015 13:07:57 UTC