XForms/Trailing Insert and Delete

Motivation
In some instances you only want to add to the end of a list or delete from the end of a list. This program demonstrates how you can use the  function to do this.

Screen Image


When you insert a new row, it will always be inserted at the end of the list. When you delete a row, it will also be removed from the end of the list.

Link to XForms Application
Insert and delete from list

Sample Program
 Repeat Demo       Value:     Insert new row   <xf:setvalue ref="val[last]" value="count(/data/val)" /> </xf:action> </xf:trigger> <xf:trigger> <xf:label>Delete last row</xf:label> <xf:delete nodeset="val" at="last" ev:event="DOMActivate" /> </xf:trigger>

Discussion
Notice that the  uses the   element to trigger on the DOM activate and the   uses the   attribute to trigger the delete. This is because we need to include the  in the insert.

So, as a general rule, if you just need to use a single element in a trigger, you can use the  attribute. But if you need to include several elements that all must be triggered you should wrap them in an an  element.

Potential problem: when you have deleted all the nodes, the insert trigger does not work anymore. This is because the nodeset selection on the insert element is empty in that situation. If the nodeset selector is empty, the insert trigger has no meaning (see the first rule in 'rules for insert processing')