Spill-over from #569542: Button Option Field is Required, has One Option - Select that Option and #368771-24: Create Documentation about removing N/A option for not required radio buttons:
From http://www.w3.org/TR/html401/interact/forms.html#h-17.2.1 (I tried to find an XHTML version of this section, and failed):
If no radio button in a set sharing the same control name is initially "on", user agent behavior for choosing which control is initially "on" is undefined. [snip] Since user agent behavior differs, authors should ensure that in each set of radio buttons that one is initially "on".
See also http://www.ietf.org/rfc/rfc1866.txt
The recommendation is basically saying that there should never be a situation where radio buttons appear that do not have one of the options pre-selected. Mainly, I guess, because you can never "un" select one of the options in a list of radios once you click into it. If you want a control where users have to explicitly choose something, you should use a select box instead which can have a 'neutral' option.
What CCK (and presumably Field UI) does is, for required fields, always select the first one in the list. For non-required fields, it automatically creates an "N/A" option to give people the ability to not fill out the field.
Basically, I guess the question is... should Form API enforce this recommendation, and disallow radio button controls without a #default_value (probably defaulting to the first option if none is selected)? People who still wanted "N/A" as one of the choices could still add it in there as one of the $options.
Anyone here web a standards geek?
Comments
Comment #1
ekes commentedRelated (presently) 7.x issue #811542: Regression: Required radios throw illegal choice error when none selected
Comment #2
roderikClients regularly want options in a form to:
- be required
- be displayed as radio buttons - because, "you know, they look better/more intuitive than a select box"
- not have any option preselected - because that is better to prevent wrongly entered data. (Depending on client profession: "it's better for conversion".)
They don't know why that isn't possible. Heck, I still never figured it wasn't possible, and am being bitten by #1 now.
So...
Here's a wild idea for the radiobuttons widget, that will
- always conform to W3C specs
- not enable ignorant site builders like myself to set up an 'invalid' state
- educate these people about why this is the case.
Idea:
A required field with radio buttons must have a default value.
Sets of radio buttons in a browser must always have one option selected, as per W3C specifications [link]. Fields which are not 'required', will therefore have an extra radio button labeled "N/A" above the regular options, which can be used to 'unselect' the field value. Required fields will also have an extra radio button on the screen (labeled "Select a value"), if a default value is not chosen here.
@webchick: with the above, the answer to your questions is "yes, let's have Form API enforce this recommendation." But not by
disallowingenforcing default values.And what about people who do not want to have this "Select a value" option for required / "N/A" option for non-required fields, as in #368771: Create Documentation about removing N/A option for not required radio buttons?
Let them hide it using CSS. Make it easy to do so, by providing a CSS selector if that isn't there yet / documentation.
That may seem like an ugly hack, but at least it's predictable (there is no 'unspecified state => unpredictable browser behavior'). And no back-end troubles; no way to hit bugs like #811542 by setting up a radiobuttons widget with an invalid state -- also not when you set up a 'required field without default value' with a select box first, and then switch the widget to radio buttons.
Comment #15
smustgrave commentedCurrently going through the end of the queue to see what could still be relevant for D10.
Wonder if this is still needed for D10?
Comment #17
quietone commentedAlmost 2 years later and no response was given about this being needed or not. So, closing this issue,
If this needs to be done, wither re-open the issue and add a comment or open a new issue and reference this one.