After some answers received on the Github Issue for HTML I filed, I decided to make the same proposal here, in order to see if there can be some agreeing.
Form validation is not meant to natively handle complex cases, as validity methods allow authors to program complex form validations. But there’s a use-case which could easily be supported, and in a sense it is already supported, that is, alternative “required” controls.
required attribute is specified on radio buttons, it is required that one of the alternatives in the radio button group is selected. This cannot be different, for obvious reasons.
There are other cases, though, when an alternative is required. For example when a user is requested to provide either a phone number or an email (in two different fields in order to benefit from “type” constraint validation), or to subscribe a newsletter, specifying at least one interest among a series of alternative with checkboxes (the user can specify more than one).
So, my proposal is to extend the “required” behavior applied to radio groups to every group of form controls sharing the same
name attribute value. Adding square brackets to names (
<input name="foo" />) allows server-side script to process more values sharing the same name, so there will be no issue in submitting more than one checked box or more than one filled-in field.
EDIT: looks like square brackets aren’t even necessary for all server-side script languages (that is for PHP). Of course the whole proposal remains the same.