[whatwg] Form element invalid message

Ian Hickson ian at hixie.ch
Wed Jul 27 17:21:10 PDT 2011


On Fri, 29 Apr 2011, Jonas Sicking wrote:
> On Fri, Apr 29, 2011 at 3:42 PM, Ian Hickson <ian at hixie.ch> wrote:
> > On Wed, 29 Dec 2010, Mounir Lamouri wrote:
> >> On 12/29/2010 07:41 AM, Ian Hickson wrote:
> >> >>
> >> >> I actually think that the customerrormessage attribute that has 
> >> >> been suggested is a decent solution too. [...]
> 
> For example, if I go to www.google.com and click on the "sign in" link 
> at the top, then without entering anything press the "sign in" button. 
> At this point the page displays a error message in red that says "Enter 
> your email address." [...]
> 
> In general it makes a lot of sense to want to display a different 
> message when the user has failed to enter a valid value in a field. 
> Clearly the user failed to enter what was requested the first time, and 
> so the context around the field was not enough for the user to enter 
> what was requested. Hence a more detailed description is appropriate.
> >
> > I don't understand how such an attribute would work. Take <input 
> > type=number> for example, with an explicit min, max, step, etc. How 
> > would you know what value to put in the attribute? There are going to 
> > be different needs when the control's value is too low, too high, not 
> > aligned to a step, missing, etc.
> 
> Consider the example above from googles login page. Here there are two 
> possible errors:
> 
> 1. The field is empty
> 2. The field doesn't contain an email address
> 
> In both cases the message "Enter your email address." seems appropriate. 
> And it seems better than what we as a browser could generate.

A text input field could have a number of error conditions:

   <label> Offer code:
    <input type=text maxlength=8 pattern="[a-z1-9]+" required>
   </label>

Suppose the code is printed as two groups of four characters, for example 
something like "1A2B 3C4D".

The user could have entered the code with the space (the site doesn't want 
the space). Or the user could have read an O as a 0 (the code never has 
any zeroes to avoid that). Or the user could have forgotten to enter the 
code. In each of these cases, I think you'd want a different message.


Anyway. I guess we can have a dedicated attribute that user agents can use 
to provide a message, rather than the current solution of just using the 
title="" attribute for pattern=""'s error message. If it's present, user 
agents could use it to replace or augment their message, and authors could 
make the message more specific by dynamically changing the attribute when 
during the 'invalid' event handler.

   <label> Offer code:
    <input type=text maxlength=8 pattern="[a-z1-9]+" required
           oninput="setCustomValidity(input.match(/0/) ?
                    'Codes contain no zeroes, only Os.' : '')"
           validitymessage="Enter the code without spaces.">
   </label>


If we add this, do you think it should be displayed with, instead of, or 
replaced by the setCustomValidity() message, when both are given?

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'


More information about the whatwg mailing list