I implemented a filter that stop users entering the wrong thing.  I figured 
if TextBox.setMaxLength does it, then why not.

However, as Thomas pointed out, it's hard to do properly.  I ended up 
allowing the invalid input and then removing it in a scheduleDeferred 
command.  Not ideal as the user sees the invalid input flash up, but it at 
least works on all browsers.


On Saturday, April 21, 2012 4:48:06 AM UTC+10, Alfredo Quiroga-Villamil 
wrote:
>
> @Jen:
>
> Your code and something along the lines to what you proposed would 
> certainly work and be flexible enough.
>
> @Andrei:
>
> "When a user presses a button and nothing happens, many users would assume
> that your app is broken (they did press a letter for some reason!)"
>
> You always know when/what the user typed. The app would not look broken if 
> upon the keydown and read of the key you know that it doesn't meet the 
> specification and right away let the user know that "You can only type xxxx 
> here"
>
> Alfredo
>
> On Fri, Apr 20, 2012 at 2:38 PM, Jens <[email protected]> wrote:
>
>> I always try to keep in mind that GWT is a tool kit. However, when a 
>>> class is named IntegerBox, to be used in a UI, yeah I expect it to be type 
>>> safe and also do what its name implies in the UI as well 
>>> as programmatically. In this case only allow Integers to be typed in.
>>>
>>
>> Some years ago when doing ordinary desktop applications I would probably 
>> expect the same. But today developing web applications my mind shifted and 
>> I found it more important to be liberal on the user input but tell the user 
>> if they have done something wrong. This just feels more like things work on 
>> the web and I want to preserve this feeling even in web applications 
>> because thats what people are used to when using the web.
>> Also inexperienced users may think their keyboard is somehow broken if 
>> nothing happens when typing a letter into an input box because its just so 
>> uncommon on the web to swallow user input.
>>
>>
>> In any case, I'll hang on to this email and instead of talking more, 
>>> perhaps when I have some free time I'll just get to it and see if I can add 
>>> the implementation for it, test it across browsers and submit it for a 
>>> patch review. No promises since I am really busy these days, but we'll see.
>>>
>>
>> Maybe it can be as easy as:
>>
>> IntegerBox() {
>>  this(false); //makes sure that, by default, you get the same behavior as 
>> of today
>> }
>>
>> IntegerBox(bolean strictMode) {
>>  super(Document.get().createInputElement(), IntegerRenderer.instance(), 
>> IntegerParser.instance(), strictMode ? IntegerInputValidator.instance() : 
>> null);
>> }
>>
>> along with an additional constructor in ValueBox -> ValueBoxBase taking 
>> the input validator. If an input validator is present, ValueBoxBase 
>> attaches a key handler and routes key events through the validator (which 
>> can decide to swallow the key). That way you can opt-in to your desired 
>> behavior (you dont change behavior of existing apps) and you pretty much 
>> only have to implement input validators.
>>
>>  
>>
>>> Appreciate the responses.
>>>
>>
>> You are welcome 
>>
>> -- J.
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Google Web Toolkit" group.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msg/google-web-toolkit/-/PG8WHFAnWBEJ.
>>
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to 
>> [email protected].
>> For more options, visit this group at 
>> http://groups.google.com/group/google-web-toolkit?hl=en.
>>
>
>
>
> -- 
> Alfredo Quiroga-Villamil
>
> AOL/Yahoo/Gmail/MSN IM:  lawwton
>
>
>  

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-web-toolkit/-/VrgskPK6CGoJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to