AjaxButton does not respect return false on client side

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

AjaxButton does not respect return false on client side

Entropy
I have an ajax button that launches a modal form.  It binds to:

<input type="button" wicket:id="btnCopy" onclick='return false;' value="Copy To">

I've replace the javascript call that checks the condition with a flat return false to simplify things.  This still launches the event, and renders the modal window.  

The button code itself:

                AjaxButton btnCopy = (AjaxButton) new AjaxButton("btnCopy") {
                        private static final long serialVersionUID = 1L;
                        @Override
                        public void onSubmit(AjaxRequestTarget target, Form<?> arg1) {
                                onSRTabCopy(target);
                        }
                       
                        @Override
                        public boolean isEnabled() {
                                return true;
                        }
                }.setDefaultFormProcessing(false);

Is wicket doing something to get in front of my return false?
Reply | Threaded
Open this post in threaded view
|

Re: AjaxButton does not respect return false on client side

Entropy
So I figured out that what's happening is that evidently wicket 6 doesn't put the javascript inline, but uses event listener registration or whatever.  And it seems like this overwrites my inline event in an AjaxButton.  The solution:

                        @Override
                        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
                                super.updateAjaxAttributes(attributes);
                                AjaxCallListener listener = new AjaxCallListener();
                                listener.onPrecondition("return copyClick();");
                                attributes.getAjaxCallListeners().add(listener);
                        }

However, no sooner do I solve this, then I find that one of my submit buttons (which is just a new Button, not AjaxButton) is having a similar problem.  But the above method does not exist on mere Button.  How can I do something similar?
Reply | Threaded
Open this post in threaded view
|

Re: AjaxButton does not respect return false on client side

Entropy
Nevermind.  This secondary issue was caused by one of my many experiments to solve the original issue.  Further, I also found that if I had needed to do this, the method to override is getOnClickScript().

I will say, that I am a little uncertain if this new style is a good thing.  Traditionally, Wicket has seemed to work pretty hard to make HTML things stay in HTML and Java things stay in Java.  I now seem forced to put javascript code that controls buttons in Java.  

I've put javascript in my java before of course, but usually only when the javascript needed dynamic elements from the server.  Now this seemingly client-side behavior is pulled into the server.

But my problems is resolved.
Reply | Threaded
Open this post in threaded view
|

Re: AjaxButton does not respect return false on client side

Martin Grigorov-4
hi,

On Apr 21, 2014 6:30 PM, "Entropy" <[hidden email]> wrote:
>
> Nevermind.  This secondary issue was caused by one of my many experiments
to
> solve the original issue.  Further, I also found that if I had needed to
do
> this, the method to override is getOnClickScript().
>
> I will say, that I am a little uncertain if this new style is a good
thing.
> Traditionally, Wicket has seemed to work pretty hard to make HTML things
> stay in HTML and Java things stay in Java.  I now seem forced to put
> javascript code that controls buttons in Java.
>
> I've put javascript in my java before of course, but usually only when the
> javascript needed dynamic elements from the server.  Now this seemingly
> client-side behavior is pulled into the server.

no one stops you to use plain non obtrusive JavaScript for this requirement

>
> But my problems is resolved.
>
> --
> View this message in context:
http://apache-wicket.1842946.n4.nabble.com/AjaxButton-does-not-respect-return-false-on-client-side-tp4665497p4665499.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>