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 Three or Four was the selected option then I''d get 1,2,3 or 4 from $F, but if the first option''s selected then I get "--SELECT--" back. Is this how $F is supposed to work? Eifion <select name="mr_select" id="mr_select"> <option value="">--SELECT--</option> <option value="1">One</option> <option value="2">Two</option> <option value="3">Three</option> <option value="4">Four</option> </select>
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 > Three or Four was the selected option then I''d get 1,2,3 or 4 from $F, > but if the first option''s selected then I get "--SELECT--" back. > > Is this how $F is supposed to work? > > Eifion > > <select name="mr_select" id="mr_select"> > <option value="">--SELECT--</option> > <option value="1">One</option> > <option value="2">Two</option> > <option value="3">Three</option> > <option value="4">Four</option> > </select>I complained about this a few days ago. That''s just how it works and it''s a bug IMHO. The only way I know how to deal with it is to use a "0" instead of "" and then change the server side code to deal with that. -- Michael Peters Developer Plus Three, LP
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
I''m sure that is valid in HTML, the value returned by a select,checkbox or radio is the value attribute or text node if value is not available. On 08/07/06, Eric Anderson <eric-ANzg6odk14w@public.gmane.org> wrote:> 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-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >-- Andrew Tetlaw htp://tetlaw.id.au
Andrew Tetlaw wrote:> I''m sure that is valid in HTML, the value returned by a > select,checkbox or radio is the value attribute or text node if value > is not available.But the difference between what Prototype does and what every other browser does is that if the value is specified, but is an empty string (<option value="">--choose--</option>), browsers will return send "", but Prototype sends "--choose--". -- Michael Peters Developer Plus Three, LP
On 7/8/06, Michael Peters <mpeters-aUYv5hkjw45l57MIdRCFDg@public.gmane.org> wrote:> Andrew Tetlaw wrote: > > I''m sure that is valid in HTML, the value returned by a > > select,checkbox or radio is the value attribute or text node if value > > is not available. > > But the difference between what Prototype does and what every other browser does > is that if the value is specified, but is an empty string (<option > value="">--choose--</option>), browsers will return send "", but Prototype sends > "--choose--".For what its worth, it was my patch that introduced this behavior and even *I* think its broken. Feel free to submit a patch; there are probably half a dozen tickets open at dev.rubyonrails.org for this very issue. I''d do it myself, but I''m sick of being ignored by Sam. Todd "disgruntled contributor" Ross
Yeah , you''re right, it should test for the existance of the attribute instead On 09/07/06, Michael Peters <mpeters-aUYv5hkjw45l57MIdRCFDg@public.gmane.org> wrote:> > > Andrew Tetlaw wrote: > > I''m sure that is valid in HTML, the value returned by a > > select,checkbox or radio is the value attribute or text node if value > > is not available. > > But the difference between what Prototype does and what every other browser does > is that if the value is specified, but is an empty string (<option > value="">--choose--</option>), browsers will return send "", but Prototype sends > "--choose--". > > -- > Michael Peters > Developer > Plus Three, LP > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >-- Andrew Tetlaw htp://tetlaw.id.au
Michael Peters
2006-Jul-09 19:25 UTC
Maintainer? [WAS: $F - Is this the correct behaviour]
Todd Ross wrote:> I''d do it myself, but I''m sick of being ignored by Sam. > > Todd "disgruntled contributor" RossI have to admit that it''s kind of depressing to work with an open source project with a distant (I''m sure others would use a stronger adjective) maintainer. I can''t say that I''ve ever seen Sam Stephenson on the mailing list and according to comments from others, he doesn''t seem to pay too much attention to the bug tracker either. Does he prefer some other medium of communitcation? As a user and want-to-be-contributor, it would be nice to hear about his roadmap for future development, what things he wants help on, why some patches are rejected, or even if he no longer has interest in the project. Although I''m not a Rails person, the 4th section of rubyonrails.com is titled "Get Involved". -- Michael Peters Developer Plus Three, LP
Andrew Kaspick
2006-Jul-09 20:17 UTC
Re: Maintainer? [WAS: $F - Is this the correct behaviour]
Could always fork it and implement all the outstanding fixes into a new branch. Of course it wouldn''t be distributed with rails, but if enough people start using the "improved" version then who knows what may happen. Of course this isn''t the optimal solution, but at this point I''d opt for the "improved" version. Andrew On 7/9/06, Michael Peters <mpeters-aUYv5hkjw45l57MIdRCFDg@public.gmane.org> wrote:> > > Todd Ross wrote: > > I''d do it myself, but I''m sick of being ignored by Sam. > > > > Todd "disgruntled contributor" Ross > > I have to admit that it''s kind of depressing to work with an open source project > with a distant (I''m sure others would use a stronger adjective) maintainer. I > can''t say that I''ve ever seen Sam Stephenson on the mailing list and according > to comments from others, he doesn''t seem to pay too much attention to the bug > tracker either. Does he prefer some other medium of communitcation? > > As a user and want-to-be-contributor, it would be nice to hear about his roadmap > for future development, what things he wants help on, why some patches are > rejected, or even if he no longer has interest in the project. > > Although I''m not a Rails person, the 4th section of rubyonrails.com is titled > "Get Involved". > > -- > Michael Peters > Developer > Plus Three, LP > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >