Eifion wrote:
I was using $F today to read the value of a SELECT element and found
that if the value of one of the options is an empty string, the option's
text is returned instead. For example in the code below, if One, Two
[...snipped example...]
Is this how $F is supposed to work?
The short answer is no, it is a bug.
You can fix it up. Just look for the "selectOne" and "selectMany" method
in form.js. You will see a line that looks like this:
value = opt.value || opt.text;
This line is using a side-effect of the || operator to default the value
to "opt.text" if "opt.value" is false. In a language like Ruby this
works because only nil and false evaluate to false. In Javascript the
following values evaluate to false:
null
undefined
NaN
0
-0
""
Therefore the valid value of "" get's overlooked and Prototype get's the
value from the contents of the option tag.
Eric
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs