<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>22276</bug_id>
          
          <creation_ts>2013-06-05 05:19:44 +0000</creation_ts>
          <short_desc>Content model of datalist described inconsistently</short_desc>
          <delta_ts>2013-06-21 15:51:22 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WHATWG</product>
          <component>HTML</component>
          <version>unspecified</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows NT</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>Unsorted</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Jukka K. Korpela">jukka.k.korpela</reporter>
          <assigned_to name="Ian &apos;Hixie&apos; Hickson">ian</assigned_to>
          <cc>ian</cc>
    
    <cc>mike</cc>
          
          <qa_contact>contributor</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>88696</commentid>
    <comment_count>0</comment_count>
    <who name="Jukka K. Korpela">jukka.k.korpela</who>
    <bug_when>2013-06-05 05:19:44 +0000</bug_when>
    <thetext>The content model of &lt;datalist&gt; is described thusly:

“Either: phrasing content.
Or: Zero or more option elements.”

This clearly says that &lt;datalist&gt;foo&lt;/datalist&gt; is OK and so is &lt;datalist&gt;&lt;option&gt;&lt;/datalist&gt; but &lt;datalist&gt;foo&lt;option&gt;&lt;/datalist&gt; is not (because it’s either or).

Yet, the prose text says: “The contents of the element represents fallback content for legacy user agents, intermixed with option elements”.  And http://validator.nu plays by this principle; it accepts &lt;datalist&gt;foo&lt;option&gt;&lt;/datalist&gt;.

A minimal fix would be to change the content model description to

“Phrasing content and option elements”

but perhaps the following more formal description is needed instead:

“Phrasing content optionally intermixed with option elements”.

This content model implies that any option element should be explicitly closed with a closing tag, e.g. &lt;option value=foo&gt;&lt;/option&gt;, if it is followed by phrasing content. Otherwise the phrasing content will be parsed as option element content, possibly causing a syntax error.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>89110</commentid>
    <comment_count>1</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-06-11 18:26:03 +0000</bug_when>
    <thetext>The content model is right, but you&apos;re right that I should make it clearer what&apos;s going on.

The idea is that if you want to do fallback, you do it with a &lt;select&gt; element inside the &lt;datalist&gt; element. I&apos;ll add an example or something.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>89241</commentid>
    <comment_count>2</comment_count>
    <who name="Jukka K. Korpela">jukka.k.korpela</who>
    <bug_when>2013-06-13 10:47:36 +0000</bug_when>
    <thetext>(In reply to comment #1)

&gt; The content model is right

So is the validator wrong? And the prose text? It says: “The contents of the element represents fallback content for legacy user agents, intermixed with option elements that represent the predefined options.” I don’t see how this could be possible if the content model, with “or” at top level, is right.

&gt; The idea is that if you want to do fallback, you do it with a &lt;select&gt;
&gt; element inside the &lt;datalist&gt; element. I&apos;ll add an example or something.

An example or two would help indeed.

My intuitive understanding was that since &lt;datalist&gt; is something associated with a control, feeding predefined alternatives into it, the natural content would be descriptive prose, possibly mentioning some examples as
alternatives, e.g. as in

&lt;label for=&quot;dest&quot;&gt;Destination city:&lt;/label&gt;
&lt;input name=&quot;dest&quot; list=&quot;cities&quot;&gt;
&lt;datalist id=&quot;cities&quot;&gt;
&lt;br&gt;(Enter city name, e.g. Helsinki, Espoo, or Turku.)
&lt;option value=&quot;Helsinki&quot;&gt;
&lt;option value=&quot;Espoo&quot;&gt;
&lt;option value=&quot;Turku&quot;&gt;
&lt;/datalist&gt;

If the content model is right, this is not allowed. I don’t see how using &lt;select&gt; elements would help. On old browsers, &lt;select&gt; would create a dropdown menu, so there would be a text field *and* a dropdown, for the same data.

Do you mean that the approach would be something like the following: 

&lt;label for=&quot;dest&quot;&gt;Destination city:&lt;/label&gt;
&lt;input name=&quot;dest&quot; list=&quot;cities&quot;&gt;
&lt;datalist id=&quot;cities&quot;&gt;
&lt;br&gt;(Type a city name in the bow above or select it from the list below:)&lt;/br&gt;
&lt;select name=&quot;dest&quot;&gt;
&lt;option value=&quot;Helsinki&quot;&gt;
&lt;option value=&quot;Espoo&quot;&gt;
&lt;option value=&quot;Turku&quot;&gt;
&lt;select&gt;
&lt;/datalist&gt;

Then I guess the description should be clarified, saying that the .options IDL attribute returns a collection of all option elements that a descendants of the &lt;datalist&gt; element, not just direct children. Note that the current wording for datalist.options says “Returns an HTMLCollection of the options elements of the table”, where “table” must be a slip; the sentence should probably end with “the option elements inside the datalist element” (corresponding to the more formal text after the statement).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>89710</commentid>
    <comment_count>3</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-06-21 15:49:35 +0000</bug_when>
    <thetext>I&apos;ve tried to clarify the spec. Thanks for the feedback!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>89711</commentid>
    <comment_count>4</comment_count>
    <who name="">contributor</who>
    <bug_when>2013-06-21 15:51:22 +0000</bug_when>
    <thetext>Checked in as WHATWG revision r7993.
Check-in comment: Clarify &lt;datalist&gt; content model.
http://html5.org/tools/web-apps-tracker?from=7992&amp;to=7993</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>