GWT pasting event

橙三吉。 提交于 2019-11-30 04:02:21

问题


I want to handle events when user pastes some text in TextBox. Which event is fired in this situation? I tried ValueChange and Change handlers, but they didn't work.


回答1:


This might help you. Describes a workaround to hook to the onpaste event. In short:

  • subclass TextBox

  • sink the onpaste event in the constructor

    sinkEvents(Event.ONPASTE);
  • override onBrowserEvent(Event event)

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



回答2:


GWT does not yet have support for cut, copy & paste: http://code.google.com/p/google-web-toolkit/issues/detail?id=4030

Edited: Another option is to use JSNI. For example add this to your GWT class:

public native void addCutHandler(Element element)
    /*-{
        var temp = this;  // hack to hold on to 'this' reference
        element.oncut = function(e) {
            temp.@org.package.YourClass::handleCut()();
        }
    }-*/;

public void handleCut() {
    Window.alert("Cut!");
}



回答3:


**(Write In the Constructor)**

sinkEvents( Event.ONPASTE );   

**(After that write below code)**

public void onBrowserEvent( Event event )
{
    super.onBrowserEvent( event );
    switch ( event.getTypeInt() )
    {
        case Event.ONPASTE :
        {
             event.stopPropagation();
             event.preventDefault();
             break;
        }
    }
}


来源:https://stackoverflow.com/questions/4018118/gwt-pasting-event

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!