These forums are currently read-only due to receiving more spam than actual discussion. Sorry.

It is currently Sat Dec 02, 2017 4:03 pm Advanced search

HTMLCollection, options and datalist runaround

Do you think the HTML spec should do something differently? You can discuss spec feedback here, but you should send it to the WHATWG mailing list or file a bug in the W3C bugzilla for it to be considered.

HTMLCollection, options and datalist runaround

Postby Ruzz » Thu May 31, 2012 9:09 pm

I've spoken to Ian Hixie about this before but, well, we couldn't seem to agree. Today, a closely related "issue" has come up so I decided to post here since it brings the spec into question (again).

Aside: for some background, interested readers may wish to visit https://bugzilla.mozilla.org/show_bug.cgi?id=720385)

In this post I want to highlight the "hole" I think that exists in the specs for datalist.

Code: Select all
<datalist id="myDL">
  <option value="zero"></option>
  <option value="one"></option>
  <option value="two"></option>
  <option value="three"></option>
  <option id="blah" value="four"></option>
</datalist>


As is now well understood (by me at least) any attempt to get the index of an option element whose parent element is a datalist is doomed to failure. It's not -1 (as anyone with any experience of the DOM might expect - clearly the mozilla guys thought so too) but, in fact is 0 (assuming a UA with spec compliance).
Code: Select all
opt = opts["blah"] ;
opt.index <-- returns 0

opt = opts[1]
opt.index <-- returns 0


However, if one takes the datalist's options collection as a starting point (options => HTMLCollection) then one *can* retrieve a given nth option element using an index and at the same time be refused its index:

Code: Select all
var opts = document.getElementById("myDL").options;
alert(opts.item(3).index + " = " + opts.item(3).value);


To save you time, the above renders: -1 = three
(Tested: Firefox 12 and, if I've read everything correctly, is perfectly (but laughably) correct).

Where the spec is at fault (IMO): It talks about "list of options" and defines them as differing between lists of options belonging to a select element and lists of options belonging to a datalist element. Why? To what end? For what meaningful purpose? The crazy thing is, to conform, UAs will be writing extra and unnecessary code just to comply. Notionally:
Code: Select all
function getOptIndex(opt) {
  if my parent is a datalist
    return 0;
  else
    return opt.index;
}

IMO, a datalist should be "a list" and behave as "a list". i.e. as any "common man" might expect: a list has implied order and the order is (should/must) be discoverable (please, check your OL and UL baggage at the door ;)

Ruzz
Ruzz
<h6>
 
Posts: 4
Joined: Tue Oct 19, 2010 1:37 pm
Location: @CodaCoder

Re: HTMLCollection, options and datalist runaround

Postby zcorpan » Fri Jun 01, 2012 5:02 pm

Please file a spec bug. :)

What was it you discussed with Hixie before?
zcorpan
<article>
 
Posts: 807
Joined: Tue Feb 06, 2007 8:29 pm
Location: Sweden

Re: HTMLCollection, options and datalist runaround

Postby Ruzz » Fri Jun 08, 2012 2:25 am

zcorpan wrote:Please file a spec bug. :)


Jeez... I hope it's an easy thing to do!

What was it you discussed with Hixie before?


Oh... just that I thought it was a dumb name for an element that doesn't support "listness" (indices, discover-ability, etc) and (in Ian's view) isn't intended for "data". Anyway, I sent Ian a link to this thread so he may jump in with more talk about semantics and bananas (that's a joke, Ian, ok?) :D

Ruzz
Ruzz
<h6>
 
Posts: 4
Joined: Tue Oct 19, 2010 1:37 pm
Location: @CodaCoder

Re: HTMLCollection, options and datalist runaround

Postby zcorpan » Sat Jun 16, 2012 12:09 pm

Ruzz wrote:Jeez... I hope it's an easy thing to do!

Sure is. The spec at http://whatwg.org/html has a box at the bottom from which you can file a spec bug. If you want to comment on the bug you need to create an account on the W3C bugzilla. Ask in #whatwg on Freenode if you need any help.
zcorpan
<article>
 
Posts: 807
Joined: Tue Feb 06, 2007 8:29 pm
Location: Sweden

Re: HTMLCollection, options and datalist runaround

Postby Adhori Yaadin » Wed Mar 04, 2015 10:12 am

It talks about "list of options" and defines them as differing between lists of options belonging to a select element and lists of options belonging to a datalist element.

_________________
Arslan1
Adhori Yaadin
<h6>
 
Posts: 1
Joined: Wed Mar 04, 2015 10:11 am


Return to Feedback on the Specs

Who is online

Users browsing this forum: No registered users and 1 guest