* marc-olivier bernard wrote (11/07/06 16:57):
On 7/11/06, Chris Lear wrote:
Are you sure it's a Firefox bug? The way the builder code works is very
strange... to create an option element, it seems to create a select
element, put the option element into it, then fetch the option out of
that select element again. The result is that the option is *always*
selected. I think it's because firefox is treating it as the only
element in the select list, which means it must be selected. [When I run
your code, the last element in the list is selected, rather than the
first. If I debug the value of the "selected" attribute, it's "selected"
for all of them]
Are you speaking from the code at
http://bugzilla.mozilla.org/show_bug.cgi?id=300016#c10 ?
No. I was talking about the code you posted using scriptaculous.
How do you debug +the value of the "selected" attribute+ ? See below...
I added code like this to builder.js:
element.selected="anything";
alert(element.selected);
The alert always says "selected".
This code, which is pure DOM and has none of the builder weirdness, but
sets attributes in the same way, works in Firefox:
var dr=document.createElement("select");
var op=document.createElement("option");
op.appendChild(document.createTextNode("any"));
dr.appendChild(op);
op=document.createElement("option");
op.appendChild(document.createTextNode("all"));
op["selected"]="selected"; // <- attribute set here
The last line ^^^^ is not using the DOM API, but I agree that your
solutions works in Firefox.
It isn't using the DOM API, I agree. I lied when I said it was pure DOM.
Sorry about that. I did it that way because that's what the
scriptaculous builder does, and I was trying to emulate that.
Nevertheless, I suspect it is not for the
good reason: if I inspect the resulting DOM Tree (with Firefox DOM
Inspector), your solution gives:
<select>
<option>any</option>
<option>all</option>
<option>none</option>
</select>
while the solution given in
http://bugzilla.mozilla.org/show_bug.cgi?id=300016#c10 gives:
<select>
<option value="any">any</option>
<option selected="selected" value="all">all</option>
<option value="none">none</option>
</select>
Back to your comment
https://bugzilla.mozilla.org/show_bug.cgi?id=300016#c11, the DOM
Engine from Firefox should not make any difference within your
solution and mine, or should it?
I agree. I don't think it should. I hadn't looked at the bug report when
I posted to this list. Then I looked at the bug, and saw that you'd
presented your code differently there. I thought it would be worth
posting a working version there in case it's useful information for the
developers.
I now agree that there is a bug, but there's also a workaround, and the
builder should probably use the workaround if possible. I'm also
mystified as to why the builder works in the odd way it does.
Chris
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs