You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by scorpio2002 <d....@gmail.com> on 2011/05/01 11:10:19 UTC

SubmitLink with confirmation dialog

Hi there,
I have a SubmitLink and I'd like to add a very simple confirmation dialog to
it? Any way of doing so?

I've tried to add a SimpleAttributeModifier, but it overwrites the behaviour
in the onSubmit method of the submitlink. I think there must be an easy and
clean way of doing this.

Thank you.--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/SubmitLink-with-confirmation-dialog-tp3487505p3487505.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: SubmitLink with confirmation dialog

Posted by Pedro Santos <pe...@gmail.com>.
Hi, SubmitLink already write some JavaScript in the onclick handler, so you
need to prepend the confirmation JavaScript in order to maintain the default
behavior. e.g.

submitLink.add(new Behavior() {
onComponentTag() {
tag.put("onclick", "if(!confirm('c')) return false;" +
tag.getAttribute("onclick"));
}
});

In Wicket 1.5 RC4 you can also use the AttributeAppender to prepend the
confirmation JavaScript.

On Sun, May 1, 2011 at 4:03 PM, scorpio2002 <d....@gmail.com> wrote:

> Dear Martin,
> thank you for answering. I tried something like this:
>
> ----------------------------------------------------------
> SubmitLink link = new SubmitLink("link") {
>    public void onSubmit() { /* my stuff */}
> }
>
> link.add(new SimpleAttributeModifier("onclick", "return confirm('are you
> sure?');"));
> ----------------------------------------------------------
>
> However, weather I click 'Cancel' or 'OK', the code in the onSubmit()
> method
> never gets executed.
>
> I'm stuck, I can't believe such a framework does not support this basic
> feature O_o I must be missing something obvious ^^"
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/SubmitLink-with-confirmation-dialog-tp3487505p3488329.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
>
>


-- 
Pedro Henrique Oliveira dos Santos

Re: SubmitLink with confirmation dialog

Posted by scorpio2002 <d....@gmail.com>.
Dear Martin,
thank you for answering. I tried something like this:

----------------------------------------------------------
SubmitLink link = new SubmitLink("link") {
    public void onSubmit() { /* my stuff */}
}

link.add(new SimpleAttributeModifier("onclick", "return confirm('are you
sure?');"));
----------------------------------------------------------

However, weather I click 'Cancel' or 'OK', the code in the onSubmit() method
never gets executed.

I'm stuck, I can't believe such a framework does not support this basic
feature O_o I must be missing something obvious ^^"
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/SubmitLink-with-confirmation-dialog-tp3487505p3488329.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: SubmitLink with confirmation dialog

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

On Sun, May 1, 2011 at 11:10 AM, scorpio2002 <d....@gmail.com> wrote:
> Hi there,
> I have a SubmitLink and I'd like to add a very simple confirmation dialog to
> it? Any way of doing so?
>
> I've tried to add a SimpleAttributeModifier, but it overwrites the behaviour
> in the onSubmit method of the submitlink. I think there must be an easy and
> clean way of doing this.
SimpleAttributeModifier("onclick", yourJsHere) is the way if you want
to use JavaScript alert(). onSubmit() method is called at server side
only if onclick at the client side returned true.
>
> Thank you.--
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/SubmitLink-with-confirmation-dialog-tp3487505p3487505.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
>
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

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