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

[whatwg] select element should have a required attribute

From: Mikko Rantalainen <mikko.rantalainen@peda.net>
Date: Wed, 11 Aug 2010 12:03:48 +0300
Message-ID: <4C626774.7000003@peda.net>
2010-08-10 21:25 EEST: Tab Atkins Jr.:
> On Tue, Aug 10, 2010 at 11:12 AM, Mike Wilcox <mike at mikewilcox.net> wrote:
>> This seems like the ideal situation to use a placeholder attribute:
>>
>> <select required="true" placeholder="Select an item...">
>>    <option value="Foo"> Foo </option>
>>    <option value="Bar"> Bar </option>
>>    <option value=""> None </option>
>> </select>
> 
> Almost, but not quite.
> 
> Yes, the value used in this situation is essentially a placeholder
> value - it performs the same function as <input placeholder>.
> However, an <input type=text placeholder=foo required> will fail
> validation if the user doesn't interact with it, while a similar
> <select> will not at the moment (it will just submit the first value).
> 
> It could be possible to define the interaction of <select>,
> @placeholder, and @required in such a way that it works intelligently,
> so that the <select> with a placeholder fails validation if the user
> doesn't interact with it, but that may be too much magic.

I would prefer something like this:

<select pattern="(?!myvalue).*">
  <option value="myvalue">Select an item...</option>
  <option ...>...</option>
  ...
</select>

That is, the author should explicitly specify that the item with the
special value will not be accepted.

Stuff I don't want to see (combined with @required):

- first option is always special
- empty string as the value is special
- option without a value is special

If there needs to be some easier way to specify this but the pattern,
how about @disallow="xyz"?

-- 
Mikko

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: OpenPGP digital signature
URL: <http://lists.whatwg.org/pipermail/whatwg-whatwg.org/attachments/20100811/dcdc2469/attachment.pgp>
Received on Wednesday, 11 August 2010 02:03:48 UTC

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