0

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

Community
  • 1
  • 1
touchchandra
  • 1,506
  • 5
  • 21
  • 37

2 Answers2

3

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;
    }

}
Tobika
  • 1,037
  • 1
  • 9
  • 18
0

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 ...

Yoplaboom
  • 554
  • 3
  • 13
  • actually there is an onpaste event fired when user uses the context menu or ctrl+c http://www.gwtproject.org/javadoc/latest/com/google/gwt/user/client/Event.html#ONPASTE – Tobika Feb 01 '16 at 17:45