cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christoph Hermann <christoph.herm...@guschtel.de>
Subject Re: Repost from users list: Cforms Repeater - Cancel delete action via javascript
Date Tue, 30 Aug 2005 13:18:08 GMT
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.

Ok, thanks for making this point clear.

> 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.

Yes, that was one solution we already came up with, but i thought there
would be a better way to do this stuff.

Just for the archives, here is my solution:
---snip---
    <fd:action id="myid" repeater="myrepeater" select="select">
      <fd:label>Remove selected</fd:label>
      <fd:on-action>
    	<fd:javascript>
		var form = event.source.form;
		var repeater = form.lookupWidget("myrepeater");
		var row;
		var message;
		for (var i=repeater.size-1; i &gt;= 0; i--) {
			row = repeater.getRow(i);
			if (row.lookupWidget("select").getValue().equals(true)) {
				if (CERTAIN_CONDITION) {
					// print ("Not deleting!");
					message = i18n("MyCatalogue","You cannot delete sth that is still
referenced.");
			form.lookupWidget("message").setValue(message);
				} else {
					// print ("Deleting!");
					repeater.removeRow(i);
				}
			}
		}
	</fd:javascript>
      </fd:on-action>
    </fd:action>
---snap---

Thanks for your help!
Christoph

Mime
View raw message