Search code examples
xformsxsltforms

Can't insert after last repeat node deleted


The problem is that after I delete the only remaining row in the repeat the Add button no longers works.

Padding my post with extra stuff so that the question gets accepted

<html xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xf="http://www.w3.org/2002/xforms" xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Movie Review Selector</title>
        <model xmlns="http://www.w3.org/2002/xforms">
            <instance id="movies">
                <movies xmlns="">
                    <movie id=""></movie>
                </movies>
            </instance>
            <submission id="save" action="echo.xq" method="post" includenamespaceprefixes="" serialization="application/xml" ref="instance('movies')"/>

            </submission>
        </model>
    </head>
    <body>
            <group xmlns="http://www.w3.org/2002/xforms" ref="instance('movies')">
                <repeat nodeset="movie" id="idx">
                    <input ref="@id">
                        <label>Movie Id</label>
                    </input>
                    <trigger>
                        <label>Delete</label>
                        <delete nodeset="." ev:event="DOMActivate"></delete>
                    </trigger>
                </repeat>
                <trigger>
                    <label>Add</label>
                    <action ev:event="DOMActivate">
                        <insert nodeset="movie"></insert>
                        <setvalue ref="movie[last()]/@id" value=""></setvalue>
                    </action>
                </trigger>
                <submit submission="save">
                    <label>Submit</label>
                </submit>
            </group>
    </body>
</html>

Solution

  • You have two options:

    1. Disable the Delete button when only one item remains. The XForms Wikibook shows how: http://en.wikibooks.org/wiki/XForms/Disable_Trigger
    2. Set the origin of the rows to a different instance, not to the last row of the repeat. Read this article to see how: http://en.wikibooks.org/wiki/XForms/Insert_with_Origin

    HTH!