Textbox React on Paste (Event)

1,950 views
Skip to first unread message

StrongSteve

unread,
Mar 22, 2010, 11:38:13 AM3/22/10
to Google Web Toolkit
Hi Everybody,

Is it possible to react on the user pasting text into a GWT textbox?
(Both using STRG+V and using the right-mouse context menu Paste).

ValueChange, MouseUp, ... are not fired, as I had expected them to
do. :(

Any ideas?

Thanks in Advance for your help!
Stefan

Jim Douglas

unread,
Mar 22, 2010, 12:06:59 PM3/22/10
to Google Web Toolkit
It depends on what you're trying to do, Stefan.

You'll need to subclass TextBox, then do this:

(1) Add this to the constructor:

http://google-web-toolkit.googlecode.com/svn/javadoc/2.0/com/google/gwt/user/client/ui/UIObject.html#sinkEvents(int)
http://google-web-toolkit.googlecode.com/svn/javadoc/2.0/com/google/gwt/user/client/Event.html#ONPASTE

sinkEvents(Event.ONPASTE);

(2) Override this method:

http://google-web-toolkit.googlecode.com/svn/javadoc/2.0/com/google/gwt/user/client/ui/Widget.html#onBrowserEvent(com.google.gwt.user.client.Event)

@Override
public void onBrowserEvent(Event event)
{
super.onBrowserEvent(event);
switch (event.getTypeInt())
{
case Event.ONPASTE:
{
// do something here
break;
}
}
}

N.B.:

(1) Opera doesn't fire any cut, copy or paste events, so this won't
work in Opera.

(2) If you want to find the text that the user is about to paste and
do something special with it, this will only be possible in IE or
WebKit-based browsers (Safari & Chrome).

Reply all
Reply to author
Forward
0 new messages