Topic
2 replies Latest Post - ‏2008-03-01T03:44:47Z by SystemAdmin
SystemAdmin
SystemAdmin
265 Posts
ACCEPTED ANSWER

Pinned topic Re: nested repeats with insert

‏2008-02-26T22:14:16Z |
anyone who is following other xforms forums may have seen this before. forgive me. I'm trying to advance myself beyond reverting to php every time I need to do some data manipulation. I know that xforms is powerful enough to do things on the front-end (client-side with Mozilla), but xpathing and indexing is a total bear for me. here is my situation, any help would be appreciated.
::
I had this stupid idea that I could put together a simple open source
bulliten board application using xforms repeat, insert and delete in
just a couple of days. It seemed a piece of cake in theory, but after
nearly 60 hours I'm pulling my hair out. My insert/repeat combination
works just dandy on the first level (create a board). But I've played
around with every xpath/index combination I could think of for the other two
levels and am getting nowhere. Here's the instance structure and
repeat/insert codes below (there's a live example at
http://ztags4xforms.com/XforumBBlog/forumTesting2.xhtml )

The section "add a Board" works perfectly." I can insert anywhere
within the nodeset by simply first clicking on the input box of the
node where I'd like the new data to be inserted before.

The section "add a topic" and "add a post" section give me all kinds
of fits. I can "sometimes" get an insert at the top, but not before the selected node, and I also sometimes get the final node copying itself and popping up somewhere
unexpected along with the intended insert.
Any direction or suggestions would be greatly appreciated

<xf:model>
  <xf:instance>
   <forum xmlns="">
       <boards>
          <boardTitle/>
          <board>
             <topicTitle/>
             <topic>
                <user/>
                <date/>
                <post/>
             </topic>
           </board>
        </boards>
     </forum>
   </xf:instance>

          <!-- temporary values -->
         <xf:instance id="inst2">
               <data xmlns="">
                  <newBoardTitle/>
                  <newBoard>
                     <newTopicTitle/>
                     <newTopic>
                        <newUser/>
                        <newDate/>
                        <newPost/>
                     </newTopic>
                  </newBoard>
               </data>
         </xf:instance>
      </xf:model>

            <!--xxxxxxxx  Input the Temporary Values xxxxxxxxxx -->
            <xf:input ref="instance('inst2')/newBoardTitle">

               <xf:label>Board:</xf:label>
            </xf:input> 
            <xf:input ref="instance('inst2')/newBoard/newTopicTitle">
               <xf:label>Topic/Title:</xf:label>
            </xf:input> 
            <xf:input ref="instance('inst2')/newBoard/newTopic/
newUser">
               <xf:label>UserName:</xf:label>

            </xf:input> 
            <xf:textarea class="ansbox" ref="instance('inst2')/
newBoard/newTopic/newPost">
               <xf:label>Post:</xf:label>
            </xf:textarea>

   <!-- xxxxxxxxxxxx ADD a Board  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx --
            <!--xxxxxxxx  Insert the Temp Values to the main Elements
xxxxxxxxxx -->
            <xf:trigger>
               <xf:label>Create Board
               </xf:label>
               <xf:action ev:event="DOMActivate">
                  <xf:insert nodeset="boards"
at="index('repeatBoard')" position="before" />
                  <xf:setvalue ref="boards/
boardTitle"
                               value="instance('inst2')/
newBoardTitle" />

                  <xf:setvalue ref="boards/board/
topicTitle"
                               value="instance('inst2')/newBoard/
newTopicTitle" />
                  <xf:setvalue ref="boards/board/
topic/user"
                               value="instance('inst2')/newBoard/
newTopic/newUser" />
                  <xf:setvalue ref="boards/board/
topic/post"
                               value="instance('inst2')/newBoard/
newTopic/newPost" />
                  <xf:setvalue ref="boards/board/
topic/date"
                               value="instance('inst2')/newBoard/
newTopic/newDate" />
                  <xf:toggle case="addBoardShut"
ev:event="DOMActivate"/>
               </xf:action>
            </xf:trigger>

   <!-- xxxxxxxxxxxx ADD a Topic/Title
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->

            <!--xxxxxxxx  Insert the Temp Values to the main Elements
xxxxxxxxxx -->
            <xf:trigger>

               <xf:label>Create Topic
               </xf:label>
               <xf:action ev:event="DOMActivate">
                  <xf:insert nodeset="boards/board"
at="index('repeatBoard')" position="before" />
                  <xf:setvalue ref="boards/board/
topicTitle"
                               value="instance('inst2')/newBoard/
newTopicTitle" />
                  <xf:setvalue ref="boards/board/
topic/user"
                               value="instance('inst2')/newBoard/
newTopic/newUser" />
                  <xf:setvalue ref="boards/board/
topic/post"
                               value="instance('inst2')/newBoard/
newTopic/newPost" />
                  <xf:setvalue ref="boards/board/
topic/date"
                               value="instance('inst2')/newBoard/
newTopic/newDate" />
                  <xf:toggle case="addTopicShut"
ev:event="DOMActivate"/>
               </xf:action>

            </xf:trigger>

   <!-- xxxxxxxxxxxx ADD a Post  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx --
            <!--xxxxxxxx  Insert the Temp Values to the Main Elements
xxxxxxxxxx -->
            <xf:trigger>
               <xf:label>Enter a Post
               </xf:label>
               <xf:action ev:event="DOMActivate">
                  <xf:insert nodeset="boards/board/topic"
at="index('repeatBoard')" position="before" />
                  <xf:setvalue ref="boards/board/
topic/user"
                               value="instance('inst2')/newBoard/
newTopic/newUser" />
                  <xf:setvalue ref="boards/board/
topic/post"
                               value="instance('inst2')/newBoard/
newTopic/newPost" />
                  <xf:setvalue ref="boards/board/
topic/date"
                               value="instance('inst2')/newBoard/
newTopic/newDate" />
                  <xf:toggle case="addPostShut" ev:event="DOMActivate"/

               </xf:action>

            </xf:trigger>
         </fieldset>

   <!-- xxxxxxxxxxxx Repeat Edit Board
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->
   <xf:repeat id="repeatBoard" nodeset="boards">
               <xf:input ref="boardTitle"><xf:label>Board/Page</
xf:label>
</xf:input>
               <xf:repeat nodeset="board" id="repeatTopicTitle">
                  <xf:input ref="topicTitle"><xf:label>Topic/Title</
xf:label></xf:input>
                     <xf:repeat nodeset="topic" id="repeatUser">

                        <xf:input ref="user"><xf:label>User</
xf:label>
</xf:input>
                        <xf:input  ref="date"><xf:label>Date</
xf:label>
</xf:input>
                        <xf:textarea class="ansbox" ref="post">
                           <xf:label>Post</xf:label> </
xf:textarea>
                     </xf:repeat>
               </xf:repeat>
   </xf:repeat> <!-- endRepeat repeatBoard --> 

Message was edited by: clarkepeters
Updated on 2008-03-01T03:44:47Z at 2008-03-01T03:44:47Z by SystemAdmin