You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by sorinev <so...@gmail.com> on 2017/05/24 22:49:18 UTC

Attach ajax/javascript to CheckBox, v1.4

I have a version 7.x application where I have an Ajax component that I add
some javascript to via this method:

            @Override
            protected void updateAjaxAttributes(AjaxRequestAttributes
attributes) {
                super.updateAjaxAttributes(attributes);
                attributes.getAjaxCallListeners().add(new AjaxCallListener()
                    .onBefore("$('#button1').prop('disabled',true);"
                            + "$('#button2').prop('disabled',true);")
                    .onComplete("$('#button1').prop('disabled',false);"
                            + "$('#button2').prop('disabled',false);"));
            }

Now, I have a v1.4.17 app that I need to do the same thing to, but it's
going to be on a CheckBox (I could do AjaxCheckBox if necessary). I've tried
the various solutions I've googled, but to no avail. When the checkbox is
checked, some code runs. While that code runs, I need two buttons to be
disabled (doing it via the AjaxRequestTarget obviously won't work). When the
CheckBox's onUpdate code finishes running, the buttons can be enabled again.

This app is stuck on 1.4.17 for the foreseeable future and that's outside of
my hands.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Attach-ajax-javascript-to-CheckBox-v1-4-tp4677930.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Attach ajax/javascript to CheckBox, v1.4

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

On Thu, May 25, 2017 at 5:40 PM, sorinev <so...@gmail.com> wrote:

> I've tried adding an AjaxEventBehavior to the regular CheckBox and to the
> AjaxCheckBox. I tried a few different things, the latest one is this:
>
>         fooCheckBox.add(new AjaxEventBehavior("onbefore"){
>

There is no JavaScript named "onbefore".
You need "onchange".


>             @Override
>             protected IAjaxCallDecorator getAjaxCallDecorator(){
>                     return new IAjaxCallDecorator(){
>                         public CharSequence decorateScript(CharSequence
> script) {
>                             return "$('#button1').prop('disabled',true);"
>                                     + "$('#button2').prop('disabled'
> ,true);"
> + script;
>                         }
>
>                         public CharSequence
> decorateOnSuccessScript(CharSequence script) {
>                             return script;
>                         }
>
>
Here you probably need to enable the buttons again.


>                         public CharSequence
> decorateOnFailureScript(CharSequence script) {
>                             return script;
>                         }
>
>                     };
>             }
>
> And a similar one for oncomplete. There doesn't seem to really be much
> inside the AjaxCheckBox itself, unlike some of the other Ajax components
> that have a ton of things that can be overridden (including an internal
> getAjaxCallDecorator. There's basically just the one onUpdate method and
> that's it.
>
> I am very light on front end knowledge and sometimes wicket is hard to find
> non-api-doc info for. It's really hard to find good information for what to
> do in specific situations. So I may be going about this the wrong way, but
> like I said, I tried a few other things I found I just don't remember
> specifically what they were.
>
> --
> View this message in context: http://apache-wicket.1842946.
> n4.nabble.com/Attach-ajax-javascript-to-CheckBox-v1-4-
> tp4677930p4677932.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Attach ajax/javascript to CheckBox, v1.4

Posted by sorinev <so...@gmail.com>.
I've tried adding an AjaxEventBehavior to the regular CheckBox and to the
AjaxCheckBox. I tried a few different things, the latest one is this:

        fooCheckBox.add(new AjaxEventBehavior("onbefore"){
            @Override
            protected IAjaxCallDecorator getAjaxCallDecorator(){
                    return new IAjaxCallDecorator(){
                        public CharSequence decorateScript(CharSequence
script) {
                            return "$('#button1').prop('disabled',true);"
                                    + "$('#button2').prop('disabled',true);"
+ script;
                        }

                        public CharSequence
decorateOnSuccessScript(CharSequence script) {
                            return script;
                        }

                        public CharSequence
decorateOnFailureScript(CharSequence script) {
                            return script;
                        }
                        
                    };
            }

And a similar one for oncomplete. There doesn't seem to really be much
inside the AjaxCheckBox itself, unlike some of the other Ajax components
that have a ton of things that can be overridden (including an internal
getAjaxCallDecorator. There's basically just the one onUpdate method and
that's it.

I am very light on front end knowledge and sometimes wicket is hard to find
non-api-doc info for. It's really hard to find good information for what to
do in specific situations. So I may be going about this the wrong way, but
like I said, I tried a few other things I found I just don't remember
specifically what they were.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Attach-ajax-javascript-to-CheckBox-v1-4-tp4677930p4677932.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Attach ajax/javascript to CheckBox, v1.4

Posted by Martin Grigorov <mg...@apache.org>.
On Thu, May 25, 2017 at 12:49 AM, sorinev <so...@gmail.com> wrote:

> I have a version 7.x application where I have an Ajax component that I add
> some javascript to via this method:
>
>             @Override
>             protected void updateAjaxAttributes(AjaxRequestAttributes
> attributes) {
>                 super.updateAjaxAttributes(attributes);
>                 attributes.getAjaxCallListeners().add(new
> AjaxCallListener()
>                     .onBefore("$('#button1').prop('disabled',true);"
>

Better use #onBeforeSend(). It is called after all preconditions pass.
There is no need to disable if a precondition stops the Ajax request.


>                             + "$('#button2').prop('disabled',true);")
>                     .onComplete("$('#button1').prop('disabled',false);"
>                             + "$('#button2').prop('disabled',false);"));
>             }
>
> Now, I have a v1.4.17 app that I need to do the same thing to, but it's
> going to be on a CheckBox (I could do AjaxCheckBox if necessary). I've
> tried
>

If there is no Ajax request then how you would know when to enable it again
? It seems you need to add Ajax event behavior or use AjaxCheckBox!


> the various solutions I've googled, but to no avail. When the checkbox is
>

Which solutions did you try ?
See IAjaxCallDecorator


> checked, some code runs. While that code runs, I need two buttons to be
> disabled (doing it via the AjaxRequestTarget obviously won't work). When
> the
> CheckBox's onUpdate code finishes running, the buttons can be enabled
> again.
>
> This app is stuck on 1.4.17 for the foreseeable future and that's outside
> of
> my hands.
>
> --
> View this message in context: http://apache-wicket.1842946.
> n4.nabble.com/Attach-ajax-javascript-to-CheckBox-v1-4-tp4677930.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>