Christoph Hermann wrote:
Sylvain Wallez schrieb:
Hello,
So i'm asking you: Is there a way to cancel a repeaters delete-row
action in case a certain condition is met?
Hmm... the delete-row action accepts additional listeners, but those are
not supposed to be able to cancel the action. The "Invalid return" error
you get is because the on-action is a script snippet that has no return
value.
---snip from #cocoon---
<timlarson_> Guschtello: I see Sylvain gave the same answer, plus a code
snippet :)
<timlarson_> Does it work for you?
...
<Guschtel_> So i implemented it using a simple fd:action
works fine, but i thought there would be a "better" way :)
<Guschtel_> works fine, but i thought there would be a "better" way :)
...
<timlarson_> Yes, it seems like the cocoon code should be changed to
allow the way you tried first...you might want to send an email to that
effect to the dev list, if it bothers you much.
...
<timlarson_> sylvain did not seem to catch the idea that the cocoon code
should be changed, just that your first try would not work with the
current code.
<Guschtel_> You mean i should repost to make him rethink about it? ,)
---snap---
Maybe the Cocoon Code c(sh)ould be changed to make this possible?
Imho it would be very "natural" to allow the javascript to cancel the
action.
And it shouldn't be too difficult to implement this.
I thought about it as well, but it's not as easy as it seems though. The
moment where the event listeners are called depends on the action type
(see [1]): *before* row deletion in the case of delete-row and *after*
row addition or move for other row-actions. The general idea (for all
actions all but delete) is that event listeners are called when the
repeater is in its target state (i.e. after acting), wereas it was
considered useful for deletion event listeners to be able to get some
data from the row before it was deleted.
So allowing event listeners to cancel the action would require to change
this behaviour, which was designed to allow listeners to take
complementary actions to the main one.
In the end, my opinion is that if conditional action is needed, then
it's better to write the few corresponding lines in a regular fd:action
that has no built-in behaviour like row-actions and repeater-actions do.
Sylvain
[1] http://cocoon.apache.org/2.1/userdocs/forms/widget_repeater_action.html
--
Sylvain Wallez Anyware Technologies
http://people.apache.org/~sylvain http://www.anyware-tech.com
Apache Software Foundation Member Research & Technology Director