Interesting Things
- Radio buttons behave strangely when they have no ‘value’ attribute. If you had a form containing a tag like this:
<input type="radio" name="foo" /> (no value attribute),
and you selected that radio button, then the POST data will contain foo=on. The default value is not an empty string, but the word “on”.
You might run into this problem using rails form helpers. If you pass a nil value to ActionView’s radio_button_tag method, it will render a tag without a ‘value’ attribute, so the string “on” might show up in your params.
Radio buttons are required to have a value set, so if there is no value set then the value is undefined.
http://www.w3.org/TR/html4/interact/forms.html#adef-value-INPUT
“on” is the “sane” implementation of this undefined behavior, because a selected radio button is “on” and the others are “off”.
http://www.w3.org/TR/html4/interact/forms.html#initial-value
August 27, 2011 at 4:06 pm