Christoph Hermann wrote:
>Hello,
>
>i originally posted this question on the users list some time ago, but
>nobody did respond. After some discussion on freenode/#cocoon i decided
>to mail the dev list.
>
>So i'm asking you: Is there a way to cancel a repeaters delete-row
>action in case a certain condition is met?
>
>I tried to put a javascript "return false;" in the on-action, but this
>throws an error. (Invalid return)
>
>I think there should be a simple way to prevent the action to be
>performed, but i did not find anything in the docs. In the docs there is
>only mentionned that the on-action is performed before the delete-row.
>
>What i basically want to do is disable the deleting of rows that are
>still referenced somewhere. I.e. you have two xml documents which
>reference each other and you cannot delete a "parent"-row if there are
>still "children" in another document referencing this element.
>
>I'd be very happy if someone of you could help me with this.
>
>
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.
To achieve what you want, you should use a plain action widget with an
on-action that surrounds the row deletion with the filtering logic.
Deleting a row is rather straightforward, and here's the code behind the
delete-row widget:
Repeater.RepeaterRow row =
Repeater.getParentRow(event.getSourceWidget());
Repeater repeater = (Repeater)row.getParent();
repeater.removeRow(repeater.indexOf(row));
Which translates to JS as:
var row =
org.apache.cocoon.forms.formmodel.Repeater.getParentRow(event.source);
var repeater = row.parent;
repeater.removeRow(repeater.indexOf(row));
Sylvain
--
Sylvain Wallez Anyware Technologies
http://people.apache.org/~sylvain http://www.anyware-tech.com
Apache Software Foundation Member Research & Technology Director
|