W3C home > Mailing lists > Public > whatwg@whatwg.org > August 2010

[whatwg] select element should have a required attribute

From: Ian Hickson <ian@hixie.ch>
Date: Mon, 9 Aug 2010 23:35:24 +0000 (UTC)
Message-ID: <Pine.LNX.4.64.1008092316250.13322@ps20323.dreamhostps.com>
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>


> 2. For <select multiple>, it is possible to not select any option. The
> required attribute can be really helpful here too.

True, required="" would be useful in this scenario.


> 3. Having @required for <select> will be consistent and semantically 
> better. As I see it, with HTML5 Forms, I should be able to do 
> :not(:required) { display: none; } and still be able to submit the form 
> (I should not hide submit controls actually ;)). So, even for the simple 
> <select>'s with a non-null default, knowing it is required would be good 
> for everyone.

This will still work without required="". :-)


The reason <select> isn't able to use required="" currently is still the 
same as the reason when this came up in November, as Jon cites here:

On Mon, 9 Aug 2010, Jon Barnett wrote:
>
> http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2008-November/017583.html

...namely, we're still waiting for browsers to implement the current crop 
of new additions to forms, and adding more will just make them have a more 
buggy set of implementations. This feature is in the spec marked as a "v2" 
feature to add at some future point.


> I understand the reasoning for not implementing a bunch of new 
> attributes and functionality, I would still like to see <select 
> required> even without the other suggestions as requiring at least one 
> option element to be successful with a non-empty value.

Currently you can do this just by not providing empty values and not using 
multiple="" or size="".

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'
Received on Monday, 9 August 2010 16:35:24 UTC

This archive was generated by hypermail 2.3.1 : Monday, 13 April 2015 23:08:59 UTC