开发者

GWT pasting event

开发者 https://www.devze.com 2023-01-22 03:13 出处:网络
I want to handle events when user p开发者_开发知识库astes some text in TextBox. Which event is fired in this situation? I tried ValueChange and Change handlers, but they didn\'t work. This might help

I want to handle events when user p开发者_开发知识库astes some text in TextBox. Which event is fired in this situation? I tried ValueChange and Change handlers, but they didn't work.


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


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!");
}


**(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;
        }
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消