Read the text on ONPaste Event in gwt

489 Views Asked by At

I am facing problem to get text on ONPASTE event. Suppose i have 5 textboxes and i am using sinkEvent then how would i get the text which going to be pasted in any of the textbox

public abc() {
    super();
    TextBox t1 = new TextBox();
    TextBox t2 = new TextBox();
    TextBox t3 = new TextBox();
    TextBox t4 = new TextBox();
    TextBox t5 = new TextBox();

    sinkEvents( Event.ONPASTE );
}

@Override
public void onBrowserEvent(Event event) {
    super.onBrowserEvent( event );

    switch (DOM.eventGetType(event)) {
        case Event.ONPASTE:
            //Now here i want to read get the text which is going to be 
            //pasted in the any of the textbox
    }
}
1

There are 1 best solutions below

0
Tobika On

you have to catch the event in the textbox itself. you could extend the textbox to fire an event on onpaste event or do it quick and dirty like this:

public abc() {
    super();
    TextBox t1 = new TextBox(){

        @Override
        public void onBrowserEvent(Event event) {
            super.onBrowserEvent(event);
            checkForPastEventAndDoSomething(event);
        }
    };
    //...
}

private void checkForPastEventAndDoSomething(Event event) {
    switch (event.getTypeInt()) {
                case Event.ONPASTE:
                //Now here i want to read get the text which is going to be 
                //pasted in the any of the textbox
                break;
}