Friday, January 27, 2017

Re: How to simulate a click for a GWT button using fireEvent

I have use this.

this.getComo().addKeyPressHandler(new KeyPressHandler() {
            @Override
            public void onKeyPress(KeyPressEvent event) {
                int teclado = event.getNativeEvent().getKeyCode();
                if ((teclado == KeyCodes.KEY_ENTER)) {
                    getEntrar().fireEvent(new GwtEvent<ClickHandler>() {
                        @Override
                        protected void dispatch(ClickHandler handler) {
                            handler.onClick(null);
                        }

                        @Override
                        public com.google.gwt.event.shared.GwtEvent.Type<ClickHandler> getAssociatedType() {
                            return ClickEvent.getType();
                        }
                    });

                }
            }
        });


Em 26/01/2017 16:59, Privat escreveu:

I am trying to simulate a mouse click event on GWT (Google Web Toolkit) Application in <=IE8 (using fireEvent, not dispatchEvent)

A sample custom button can be found here: http://samples.gwtproject.org/samples/Showcase/Showcase.html#!CwCustomButton (The toggle button is easiest to see if the click was processed)


The major boilerplate for simulating the click can be found here: http://stackoverflow.com/a/6158050 (This is where I got the simulate function used below)


I have been able to successfully simulate the click event by using the following commands for IE9+ (in this case simulate used dispatchEvent)


simulate(document.getElementById("gwt-debug-cwCustomButton-toggle-normal"), "mouseover");  simulate(document.getElementById("gwt-debug-cwCustomButton-toggle-normal"), "mousedown");  simulate(document.getElementById("gwt-debug-cwCustomButton-toggle-normal"), "mouseup");    

In my application the fireEvent fails, because GWT's $wnd.event is null. (Line: 117, https://github.com/stephenh/google-web-toolkit/blob/master/user/src/com/google/gwt/user/client/impl/DOMImplTrident.java)


If there is no way to simulate the click with plain JS, then is there a way to use GWT's EventDispatcher to simulate the click?

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment