Re: <input type="number"> restricting user input to only valid characters

On Wed, 15 Jul 2009, Michael A. Puls II wrote:
> > > But, with "User agents must not allow the user to set the value to a 
> > > string that is not a valid floating point number", what does that 
> > > mean with the following?
> > > 
> > > <input type="number">
> > > 
> > > If the user types "abc", should .value return "abc" or "" or 
> > > "whatever the last valid value was"?
> > 
> > It can return either "" or a valid number. It can never return "abc".
> 
> O.K., but why a choice and not just a definite value?

Because it's up to the user agent to decide what "abc" means. Maybe the 
user agent wants to support hex entry, or maybe "abc" is really "three" 
and the UA wants to support English input. Maybe invalid inputs are 
ignored, or maybe they are treated as a shorthand for "set the value to 
nothing". Maybe the UA doesn't in fact accept keyboard entry at all, and 
requires that the user enter the number using an on-screen keypad. Or 
maybe it counts how many keys you press and uses that as the number, so 
"abc" is 3. Or maybe it just has spin-up and spin-down buttons. Or maybe 
it shows a dropdown of possible numbers to pick from.


> It'd be better to say that .value always returns "" when the value the 
> user enters isn't valid.

Why does it matter? It doesn't affect interoperability.


> O.K., so what happens with
> 
> <form action="test.py">
>     <input name="x" type="number" value="1">
> </form>
> 
> when I type "abc" in the field and submit (assuming things are not validated
> when submitting to prevent submission)?

It either submits x=1 or x= (nothing). Or it doesn't allow you to type in 
"abc", so there's no way to answer the question. Or, if it is that control 
I described that takes the number of keys entered as the number, it 
submits x=3. Or if the user agent supports the user setting the control to 
hex, and the user has done so, it submits x=2748. So long as the user 
interface makes sense to the user, it doesn't really matter.

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

Received on Wednesday, 15 July 2009 10:52:00 UTC