This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 28428 - OPTION element in DATALIST element can be empty, but validator say no
Summary: OPTION element in DATALIST element can be empty, but validator say no
Status: RESOLVED WORKSFORME
Alias: None
Product: HTML Checker
Classification: Unclassified
Component: General (show other bugs)
Version: unspecified
Hardware: PC Windows NT
: P2 normal
Target Milestone: ---
Assignee: Michael[tm] Smith
QA Contact: qa-dev tracking
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-04-07 16:23 UTC by Michael Benjamin
Modified: 2015-08-23 07:07 UTC (History)
1 user (show)

See Also:


Attachments
validator screenshot: code is correct, but validates with errors (46.76 KB, image/png)
2015-04-07 16:23 UTC, Michael Benjamin
Details

Description Michael Benjamin 2015-04-07 16:23:41 UTC
Created attachment 1595 [details]
validator screenshot: code is correct, but validates with errors

Per the W3C Recommendation, the OPTION element in a DATALIST can be empty. 

This was validating correctly up until recently. Now it validates with errors, which is not correct.

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

validator results attached
Comment 1 Michael[tm] Smith 2015-04-10 13:57:53 UTC
Thanks for taking time to reporting this but the validator is behaving as intended and correctly according to the HTML spec.

The HTML spec defines the content model of the option element with this requirement:

http://www.w3.org/TR/html5/forms.html#the-option-element
"If the element has no label attribute: Text that is not inter-element whitespace"

See the "Content Model" subsection at the URL above.
Comment 2 Michael Benjamin 2015-04-10 16:43:21 UTC
(In reply to Michael[tm] Smith from comment #1)
> Thanks for taking time to reporting this but the validator is behaving as
> intended and correctly according to the HTML spec.
> 
> The HTML spec defines the content model of the option element with this
> requirement:
> 
> http://www.w3.org/TR/html5/forms.html#the-option-element
> "If the element has no label attribute: Text that is not inter-element
> whitespace"
> 
> See the "Content Model" subsection at the URL above.


Thank you for the response. However, I'm not sure what you're saying is correct.

First, the language in the spec doesn't seem clear or definitive.

Second, and more importantly, all examples and tutorials from reputable sources (including W3C) use OPTION in DATALIST without the LABEL attribute. Every single one of these code blocks fails to pass validation.

These DATALIST examples are all meant for teaching. All fail validation.
https://www.w3.org/wiki/HTML/Elements/datalist
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/datalist
http://www.sitepoint.com/creating-autocomplete-datalist-controls/
http://www.w3schools.com/tags/tag_datalist.asp
http://www.hongkiat.com/blog/html5-datalist/
http://blog.teamtreehouse.com/creating-autocomplete-dropdowns-datalist-element

Of course, I am open to the possibility that despite all these examples, I am still wrong. If so, please advise the correct way to write the code in the pages above.
Comment 3 Michael[tm] Smith 2015-04-10 17:20:06 UTC
(In reply to Michael Benjamin from comment #2)
> Thank you for the response. However, I'm not sure what you're saying is
> correct.

I am sure that what I'm saying is correct.

> First, the language in the spec doesn't seem clear or definitive.

The language in the spec absolutely is definitive. The spec states normative requirements that must be followed. Nothing else stated informatively anywhere else can override normative requirements stated in the spec.

As to whether the spec is clear or not, it's possible for there to be some particular place where the spec may not be clear some some particular thing. The way to fix that is to raise a bug suggesting how that place in the spec could be made more clear.

But in the particular case of the option content model, it doesn't seem to me that the spec is unclear. The relevant  statement the spec makes about the option content model is, "If the element has no label attribute: Text that is not inter-element whitespace".

If there's some way that you think that could be improved to state the requirement more clearly, please file a bug against the HTML spec with your suggested improvement. 

> Second, and more importantly, all examples and tutorials from reputable
> sources (including W3C) use OPTION in DATALIST without the LABEL attribute.

Any examples that have empty option elements without labels are invalid according to the current HTML spec. The way to fix that mismatch is either to (A) file a bug against the HTML spec asking that spec be changed to say, e.g., that an empty option element without a label is allowed to occur in datalist, or to (B) file bugs or reports of some kind against whatever documents those invalid examples are in.

> Of course, I am open to the possibility that despite all these examples, I
> am still wrong. If so, please advise the correct way to write the code in
> the pages above.

Either put label attributes on all the empty option elements, or put text content inside the option elements so they're no longer empty.
Comment 4 Michael Benjamin 2015-04-10 17:48:02 UTC
(In reply to Michael[tm] Smith from comment #3)

Thank you again for taking the time to respond.

I mentioned that the spec wasn't clear or definitive because, if what you're saying is correct about the language, then the spec very clearly contradicts itself. See the first code example here:
http://www.w3.org/TR/html5/forms.html#the-datalist-element

In this example, there is no LABEL attribute and no text content in the OPTION elements. This code would not pass validation. Yet the W3C Recommendation provides this example for instructional purposes.

Regarding examples -- from various reputable and reliable sources -- with empty OPTION elements, this seems to be the norm across all web tutorials. There are no cases I have found where the OPTION element in a DATALIST uses text content or the LABEL attribute. This is probably because the spec -- as you can see from the link above -- is unclear and possibly misleading.

I'll consider your advice to file a bug report on this. In the meanwhile, I hope you'll consider allowing validation to pass for code structured in conformance with the examples in the W3 Recommendation. Thank you, again.
Comment 5 Michael[tm] Smith 2015-04-10 18:39:05 UTC
(In reply to Michael Benjamin from comment #4)
> (In reply to Michael[tm] Smith from comment #3)
> 
> Thank you again for taking the time to respond.
> 
> I mentioned that the spec wasn't clear or definitive because, if what you're
> saying is correct about the language, then the spec very clearly contradicts
> itself. See the first code example here:
> http://www.w3.org/TR/html5/forms.html#the-datalist-element
> 
> In this example, there is no LABEL attribute and no text content in the
> OPTION elements. This code would not pass validation. Yet the W3C
> Recommendation provides this example for instructional purposes.

Yeah, that's a bug in the spec. But it's important to understand that it's a bug in an informative-only non-normative part of the spec. That's because the examples don't state any requirements. That particular example could simply be dropped from the spec completely instead of being fixed, and the spec requirements would still be the same either way.

> Regarding examples -- from various reputable and reliable sources -- with
> empty OPTION elements, this seems to be the norm across all web tutorials.
> There are no cases I have found where the OPTION element in a DATALIST uses
> text content or the LABEL attribute. This is probably because the spec -- as
> you can see from the link above -- is unclear and possibly misleading.
> 
> I'll consider your advice to file a bug report on this.

FWIW, given that way that datalist works, I think it makes some sense to allow label-less option elements within datalist to be empty. But I don't feel strongly enough about it myself to spend any time of my own trying to get it changed in the spec. If you do feel strongly about it, then I think you should take the time to raise a bug about it and follow through on it.

If/when the spec does change with regard to this, I guarantee you I would update the validator relatively quickly to match the spec change.

>  In the meanwhile, I
> hope you'll consider allowing validation to pass for code structured in
> conformance with the examples in the W3 Recommendation. Thank you, again.

Thank you too but there's no way I will consider changing the validator behavior here unless/until the spec changes. There is no such thing as being "in conformance with the examples in the W3 Recommendation" or with examples anywhere else. That's because examples are informative only, so there's no way for the validator to be in conformance with them. The only thing that the validator can be in conformance with is the actual requirements in the spec.
Comment 6 Michael Benjamin 2015-04-10 22:19:34 UTC
Okay. I understand. Thank you for the clarification.

I may file a bug report in the future, but I have other pressing issues taking priority right now.
Comment 7 Michael[tm] Smith 2015-06-28 02:19:43 UTC
Seems like this is resolved, as far as the validator conformance goes.