Re: TextBox allow only numbers (gwt 1.6.4)

2009-06-30 Thread Thomas Broyer



On 30 juin, 09:22, Dominik Erbsland  wrote:
> Best solution for me would be if the framework would offer a "number
> only" TextBox - but for the moment this solution must suffice.

Have a look at the ValueSpinner widget from the Incubator:
http://code.google.com/docreader/#p=google-web-toolkit-incubator&t=Spinner

(and note that it does not prevent pasting non-numeric text, but it
recovers quite well if you do so)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~--~~~~--~~--~--~---



Re: TextBox allow only numbers (gwt 1.6.4)

2009-06-30 Thread Dominik Erbsland

thanks all for the help so far!
the solution of Pablo works for me. although I also have the problem
with CTRL+V. If the user inputs a string like that there is no
cancelKey() possible.
I added a second keyhandler doing this:

inputRufnummer.addKeyUpHandler(new KeyUpHandler() {

public void onKeyUp(KeyUpEvent event) {

if 
(!inputRufnummer.getText().matches("[0-9]*")) {
sendButton.setEnabled(false);
sendButton.setText("Not a number");
} else {
sendButton.setEnabled(true);
sendButton.setText("Send");
}
}
});

Best solution for me would be if the framework would offer a "number
only" TextBox - but for the moment this solution must suffice.





On Jun 30, 12:50 am, Thomas Broyer  wrote:
> On 29 juin, 22:38, Eric  wrote:
>
>
>
> > On Jun 29, 3:20 pm, Thomas Broyer  wrote:
>
> > > Note that "((TextBox) event.getSource()).cancelKey();" is exactly
> > > equivalent to "event.preventDefault();"
>
> > > ..and I believe the "// TODO(ECC) must be tested." really means that
> > > it *needs* to be tested (i.e. I'm almost sure that it isn't enough;
> > > I'm almost sure you also have to deal with KeyDown and/or KeyUp).
>
> > How could I write my application to recover nicely when the user
> > pastes
> > alphabetic characters into the text box?  If the user selects Ctrl (or
> > Cmd)-V,
> > or right-clicks and pastes. the browser will not invoke the keyboard
> > handler.
> > I found out that IE has an onpaste event, but that isn't universal.
>
> That's why I think "canceling keys" is not good practice (or at least
> not good enough), you should instead (or in addition, if you really
> want) either flag the field as invalid or automatically fix it (e.g.
> on KeyUp field.setText(fix(field.getText()) where fix() does something
> like a replaceAll("[^0-9]", "")).
>
> The best solution, of course, would be to use an 
> in an HTML5-aware browser (Opera for now). But in the mean time, a
> validation framework, or auto-correction work pretty well (and
> cancelling keys are just a "bonus" if you can get it to work)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~--~~~~--~~--~--~---



Re: TextBox allow only numbers (gwt 1.6.4)

2009-06-29 Thread Thomas Broyer



On 29 juin, 22:38, Eric  wrote:
> On Jun 29, 3:20 pm, Thomas Broyer  wrote:
>
> > Note that "((TextBox) event.getSource()).cancelKey();" is exactly
> > equivalent to "event.preventDefault();"
>
> > ..and I believe the "// TODO(ECC) must be tested." really means that
> > it *needs* to be tested (i.e. I'm almost sure that it isn't enough;
> > I'm almost sure you also have to deal with KeyDown and/or KeyUp).
>
> How could I write my application to recover nicely when the user
> pastes
> alphabetic characters into the text box?  If the user selects Ctrl (or
> Cmd)-V,
> or right-clicks and pastes. the browser will not invoke the keyboard
> handler.
> I found out that IE has an onpaste event, but that isn't universal.

That's why I think "canceling keys" is not good practice (or at least
not good enough), you should instead (or in addition, if you really
want) either flag the field as invalid or automatically fix it (e.g.
on KeyUp field.setText(fix(field.getText()) where fix() does something
like a replaceAll("[^0-9]", "")).

The best solution, of course, would be to use an 
in an HTML5-aware browser (Opera for now). But in the mean time, a
validation framework, or auto-correction work pretty well (and
cancelling keys are just a "bonus" if you can get it to work)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~--~~~~--~~--~--~---



Re: TextBox allow only numbers (gwt 1.6.4)

2009-06-29 Thread Eric



On Jun 29, 3:20 pm, Thomas Broyer  wrote:
> Note that "((TextBox) event.getSource()).cancelKey();" is exactly
> equivalent to "event.preventDefault();"
>
> ..and I believe the "// TODO(ECC) must be tested." really means that
> it *needs* to be tested (i.e. I'm almost sure that it isn't enough;
> I'm almost sure you also have to deal with KeyDown and/or KeyUp).

How could I write my application to recover nicely when the user
pastes
alphabetic characters into the text box?  If the user selects Ctrl (or
Cmd)-V,
or right-clicks and pastes. the browser will not invoke the keyboard
handler.
I found out that IE has an onpaste event, but that isn't universal.

Eric

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~--~~~~--~~--~--~---



Re: TextBox allow only numbers (gwt 1.6.4)

2009-06-29 Thread Thomas Broyer



On 29 juin, 21:07, nobody is perfect  wrote:
> Just implement KeyPressHandleron the onKeyPress method check the char code
> and cancel the key when appropriate.
>
> See the example at the TextBox api 
> docshttp://google-web-toolkit.googlecode.com/svn/javadoc/1.6/com/google/g...

Note that "((TextBox) event.getSource()).cancelKey();" is exactly
equivalent to "event.preventDefault();"

..and I believe the "// TODO(ECC) must be tested." really means that
it *needs* to be tested (i.e. I'm almost sure that it isn't enough;
I'm almost sure you also have to deal with KeyDown and/or KeyUp).

..but I don't really understand the OP: if you (Dominik) are able to
make it work with a KeyboardListener, what is blocking you  (what is
it that you don't understand) in converting the listener into a bunch
of Key*Handlers?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~--~~~~--~~--~--~---



Re: TextBox allow only numbers (gwt 1.6.4)

2009-06-29 Thread nobody is perfect
Just implement KeyPressHandleron the onKeyPress method check the char code
and cancel the key when appropriate.

See the example at the TextBox api docs
http://google-web-toolkit.googlecode.com/svn/javadoc/1.6/com/google/gwt/user/client/ui/TextBox.html

Regards,
Pablo


On Mon, Jun 29, 2009 at 7:05 AM, Dominik Erbsland wrote:

>
> thanks for the help so far.
> I am aware that there is a new handler system - I just can't figure
> out a way how to make a TextBox field "numbers only".
> I tried with a KeyUpHandler and a ValueChangeHandler but could not
> find suitable methods to check the input for its validity.
> any hints?
>
>
> On Jun 26, 8:21 pm, Miroslav Genov  wrote:
> > In GWT 1.6 old listener api has been deprecated and were introduced new
> > event system which is using handlers. More information about your case
> > can be taken from:
> >
> >  http://google-web-toolkit.googlecode.com/svn/javadoc/1.6/com/google/g.
> ..
> >
> >  textBox.addKeyPressHandler and so on.
> >
> >  Wish you good luck.
> >
> > Regards,
> >   Miroslav
> >
> > Dominik Erbsland wrote:
> > > I just saw that addKeyListener() is deprecated in gwt 1.6.4.
> > > Actually I just wanted to make a listener which checks the user input
> > > in a text box and allows only numbers.
> >
> > > with gwt 1.6.4 I could not figure out how to do that since I should
> > > not use the keyboard listener anymore.
> > > any hints how I can check the input with the KeyUpHandler of gwt
> > > 1.6.4?
> >
> > > thanks in advance.
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~--~~~~--~~--~--~---



Re: TextBox allow only numbers (gwt 1.6.4)

2009-06-29 Thread Dominik Erbsland

thanks for the help so far.
I am aware that there is a new handler system - I just can't figure
out a way how to make a TextBox field "numbers only".
I tried with a KeyUpHandler and a ValueChangeHandler but could not
find suitable methods to check the input for its validity.
any hints?


On Jun 26, 8:21 pm, Miroslav Genov  wrote:
> In GWT 1.6 old listener api has been deprecated and were introduced new
> event system which is using handlers. More information about your case
> can be taken from:
>
>  http://google-web-toolkit.googlecode.com/svn/javadoc/1.6/com/google/g...
>
>  textBox.addKeyPressHandler and so on.
>
>  Wish you good luck.
>
> Regards,
>   Miroslav
>
> Dominik Erbsland wrote:
> > I just saw that addKeyListener() is deprecated in gwt 1.6.4.
> > Actually I just wanted to make a listener which checks the user input
> > in a text box and allows only numbers.
>
> > with gwt 1.6.4 I could not figure out how to do that since I should
> > not use the keyboard listener anymore.
> > any hints how I can check the input with the KeyUpHandler of gwt
> > 1.6.4?
>
> > thanks in advance.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~--~~~~--~~--~--~---



Re: TextBox allow only numbers (gwt 1.6.4)

2009-06-26 Thread Miroslav Genov

In GWT 1.6 old listener api has been deprecated and were introduced new 
event system which is using handlers. More information about your case 
can be taken from:

 
http://google-web-toolkit.googlecode.com/svn/javadoc/1.6/com/google/gwt/event/dom/client/KeyPressHandler.html

 textBox.addKeyPressHandler and so on.

 Wish you good luck.

Regards,
  Miroslav

Dominik Erbsland wrote:
> I just saw that addKeyListener() is deprecated in gwt 1.6.4.
> Actually I just wanted to make a listener which checks the user input
> in a text box and allows only numbers.
>
> with gwt 1.6.4 I could not figure out how to do that since I should
> not use the keyboard listener anymore.
> any hints how I can check the input with the KeyUpHandler of gwt
> 1.6.4?
>
> thanks in advance.
> >
>   


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~--~~~~--~~--~--~---