On form submission, how could you possibly mark a checkbox/radiobutton as required?
相关问题
- Custom Attribute to Process info before a method i
- Is the conversion from '(signed) -1' to
- FlagsAttribute what for?
- Specification and correct use of (boolean) URI mat
- Axis SecureSocketFactory - Setting the constructor
相关文章
- HTML5 control
- Passing static array in attribute
- What other neat tricks does the SpecialNameAttribu
- Any way in Visual Studio to not break on throwing
- How can I type hint an attribute in Python 3.5?
- How to solve “Both use the XML type name X, use XM
- Adding additional attributes to each property of a
- Access extra attributes in join table when using t
Required checkboxes are not unusual. Practically every registration form uses some form of the "I have read and accept the User Agreement" checkbox.
If you have Opera handy try out the code below. The form won't submit unless the checkbox is checked.
I just tried it on a radio button in Firefox 4. Adding
required
to one radio input, then submitting before selecting one, triggers a "Please select one of these options" tooltip.E.g. this works:
For checkboxes, the best way is probably to pre-select it and set it to disabled. Just kidding.
To ensure one radio button in a group has been selected, either start with a default choice or validate using javascript. There are no HTML-ways to do that because every possible selection is valid.
In html5 there is a required attribute for checkboxes.
They are somehow weird, so let me quote something to explain how they work.
For checkboxes, the required attribute shall only be satisfied when one or more of the checkboxes with that name in that form are checked.
For radio buttons, the required attribute shall only be satisfied when exactly one of the radio buttons in that radio group is checked.
Of course you always have to validate server side because the client can always send you whatever he desires. Just use these methods for better user experience.
I tested required attribute for Radio Buttons today on Firefox 17.0.1 on XP SP2.
It seems to comply with the specification of required attribute for radio buttons/groups. As Firefox prompts "Please select one of these options." for both of the code snippets below:
Either you set required attribute for each of the radio buttons
Or Any One of the Radio elements
Any comments and updates are welcome.