touchchandra
touchchandra

Reputation: 1556

How to detect copy pate event on GWT FormTextArea?

I need to enable the "Save" button when user COPY - PATE something using Mouse clicks inside FormTextArea in GWT. I already tried with KeyUpHandler, ValueChangeHandler, ChangeHandler but didn't work as expected.

I already gone through Paste event on GWT

Upvotes: 0

Views: 298

Answers (2)

Tobika
Tobika

Reputation: 1062

to catch an paste event from keyboard ctrl+v or from the contextmenu you have to override the onBrowserEvent Method in your widget and catch the Event.ONPASTE.

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

    default:
        break;
    }

}

Upvotes: 3

Yoplaboom
Yoplaboom

Reputation: 554

I suppose you want enable the Save button when your textareais NOT empty.

You can use the KeyDownHandler

textArea.addKeyDownHandler(new KeyDownHandler() {

    @Override
    public void onKeyDown(KeyDownEvent event) {
        if(textArea.getValue().isEmpty){
           //disable
        } else {
           //enable
        }
    }
});

Sure, you will not be notified if user paste text via ContexMenubut you cannot do anything for that. You can use the ValueChangeHandler<String>too but it will be fired only when your textareawill lost the focus.

Hope it helps ...

Upvotes: 0

Related Questions