You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Ernesto Badillo <er...@gmail.com> on 2011/06/30 19:18:51 UTC

confirmation javascript in ajaxformloop

Hi,

I was trying to add a small script asking for confirmation before
removing an element contained in the ajaxformloop component. The first
thing I tried was the following:

<t:removerowlink onclick="javascript:return confirm('blab
la?')">Remove</t:removerowlink>

This doesn't work becasue this component's onclick handler is called
first and thus it is not possible to stop the removal. Then I
considered using a mixing like this:

http://www.nuiton.org/repositories/entry/nuiton-web/trunk/nuiton-tapestry/src/main/java/org/nuiton/web/tapestry5/mixins/Confirm.java

However, the problem here is that the removerowlink component doesn't
implement ClientElement so it is not possible to retrieve its id to
add an onclick handler.

The only option left seems to be creating my own removerowlink
component. ¿Is there any other thing I can do? ¿Is it possible to do
this with a mixin?

Thanks!

--
Ernesto Badillo

"Always code as if the person who will maintain your code is a maniac
serial killer that knows where you live."

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


Re: confirmation javascript in ajaxformloop

Posted by Ernesto Badillo <er...@gmail.com>.
Thanks a lot! Very simple workaround. I don't know why it didn't occur to me.

On Thu, Jun 30, 2011 at 1:22 PM, Kalle Korhonen
<ka...@gmail.com> wrote:
> This has been discussed a few times. The right way would be to use
> event propagation as intended, for example:
> <t:removerowlink><span id="confirmRemoval">Remove</span></t:removerowlink>
>
> Then add a handler for the nested element:
> Event.observe($('confirmRemoval'), 'click', function(event) {if
> (!confirm('are you sure to want to remove?')) event.stop();});
> to stop the event from being propagated to the actionlink handler.
>
> Since you are dealing with rows, the problem is with gathering all the
> ids of nested elements. If you used a button inside the link instead,
> you could just use its onclick handler:
> <t:removerowlink><button onclick="javascript:return confirm('blab
> la?')">Remove</button></t:removerowlink>
>
> Kalle
>
>
> On Thu, Jun 30, 2011 at 10:18 AM, Ernesto Badillo <er...@gmail.com> wrote:
>> Hi,
>>
>> I was trying to add a small script asking for confirmation before
>> removing an element contained in the ajaxformloop component. The first
>> thing I tried was the following:
>>
>> <t:removerowlink onclick="javascript:return confirm('blab
>> la?')">Remove</t:removerowlink>
>>
>> This doesn't work becasue this component's onclick handler is called
>> first and thus it is not possible to stop the removal. Then I
>> considered using a mixing like this:
>>
>> http://www.nuiton.org/repositories/entry/nuiton-web/trunk/nuiton-tapestry/src/main/java/org/nuiton/web/tapestry5/mixins/Confirm.java
>>
>> However, the problem here is that the removerowlink component doesn't
>> implement ClientElement so it is not possible to retrieve its id to
>> add an onclick handler.
>>
>> The only option left seems to be creating my own removerowlink
>> component. ¿Is there any other thing I can do? ¿Is it possible to do
>> this with a mixin?
>>
>> Thanks!
>>
>> --
>> Ernesto Badillo
>>
>> "Always code as if the person who will maintain your code is a maniac
>> serial killer that knows where you live."
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>



-- 
Ernesto Badillo

"Always code as if the person who will maintain your code is a maniac
serial killer that knows where you live."

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


Re: confirmation javascript in ajaxformloop

Posted by Kalle Korhonen <ka...@gmail.com>.
This has been discussed a few times. The right way would be to use
event propagation as intended, for example:
<t:removerowlink><span id="confirmRemoval">Remove</span></t:removerowlink>

Then add a handler for the nested element:
Event.observe($('confirmRemoval'), 'click', function(event) {if
(!confirm('are you sure to want to remove?')) event.stop();});
to stop the event from being propagated to the actionlink handler.

Since you are dealing with rows, the problem is with gathering all the
ids of nested elements. If you used a button inside the link instead,
you could just use its onclick handler:
<t:removerowlink><button onclick="javascript:return confirm('blab
la?')">Remove</button></t:removerowlink>

Kalle


On Thu, Jun 30, 2011 at 10:18 AM, Ernesto Badillo <er...@gmail.com> wrote:
> Hi,
>
> I was trying to add a small script asking for confirmation before
> removing an element contained in the ajaxformloop component. The first
> thing I tried was the following:
>
> <t:removerowlink onclick="javascript:return confirm('blab
> la?')">Remove</t:removerowlink>
>
> This doesn't work becasue this component's onclick handler is called
> first and thus it is not possible to stop the removal. Then I
> considered using a mixing like this:
>
> http://www.nuiton.org/repositories/entry/nuiton-web/trunk/nuiton-tapestry/src/main/java/org/nuiton/web/tapestry5/mixins/Confirm.java
>
> However, the problem here is that the removerowlink component doesn't
> implement ClientElement so it is not possible to retrieve its id to
> add an onclick handler.
>
> The only option left seems to be creating my own removerowlink
> component. ¿Is there any other thing I can do? ¿Is it possible to do
> this with a mixin?
>
> Thanks!
>
> --
> Ernesto Badillo
>
> "Always code as if the person who will maintain your code is a maniac
> serial killer that knows where you live."
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

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