[whatwg] select element should have a required attribute

On Mon, Aug 9, 2010 at 4:35 PM, Ian Hickson <ian at hixie.ch> wrote:
> On Fri, 18 Jun 2010, Mounir Lamouri wrote:
>>
>> I'm wondering why select element do not have a required attribute.
>
> It's impossible to submit a <select> element (without a size="" attribute
> or multiple="" attribute) without it having a value -- essentially,
> required="" is already implied.
>
>
> On Thu, 22 Jul 2010, Mounir Lamouri wrote:
>>
>> 1. A typical use case of <select> is to have <option value=''>Choose an
>> option</option> as a default value. Having @required would prevent
>> authors to write any js check when they are using <select> like that.
>
> That seems like an invalid use of <option> to me. It would be better as:
>
> ? <label> Choose an option: <select> ... </select> </label>

Many times you want the user to make an explicit choice, rather than
just leaving whatever was already selected. What many websites do is:

<label>Choose an option:
  <select>
    <option></option>
    <option>value 1</option>
    <option>value 2</option>
    <option>value 3</option>
  </select>
</label>

Or

<select>
  <option value="">Choose an option:</option>
  <option>value 1</option>
  <option>value 2</option>
  <option>value 3</option>
</select>

It would be good if it was possible to use @required together with
these usage patterns. I don't believe that any other feature of HTML
supplies the same, or similar, functionality? While authors could do

<label>Choose an option:
  <select>
    <option>value 1</option>
    <option>value 2</option>
    <option>value 3</option>
  </select>
</label>

I think there is a reason they haven't done so so far, and I don't see
that HTML5 changes any of those reasons.

While I guess we could wait for v2 for this feature, it seems like a
glaring omission and inconsistency in the way that @required works.

/ Jonas

Received on Monday, 9 August 2010 16:54:45 UTC