[whatwg] select element should have a required attribute

Mikko Rantalainen mikko.rantalainen at peda.net
Wed Aug 11 02:03:48 PDT 2010


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-0002.pgp>


More information about the whatwg mailing list