Search code examples
xforms

xforms and getting a particular value from a list


There is a small code that works with appache tomcat and chiba-3.0.0b2

<?xml version="1.0" encoding="UTF-8"?>
<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml"
    xmlns:xforms="http://www.w3.org/2002/xforms"
    xmlns:events="http://www.w3.org/2001/xml-events">
<xhtml:head>
    <xforms:model>

there is instance where to get a dynamic list

        <xforms:instance id="xs">
            <xs>
                <x kd="1" name="one"></x>
                <x kd="2" name="two"></x>
                <x kd="3" name="three"></x>
                <!-- ... -->
            </xs>
        </xforms:instance>
    </xforms:model>
</xhtml:head>
<xhtml:body>

There is a switch-case construction

<xforms:switch>

list case

<xforms:case id="list">
    <xhtml:ul>
        <xforms:itemset nodeset="instance('xs')/x">
            <xhtml:li>
                <xforms:trigger>
                    <xforms:toggle events:event="DOMActivate" case="onerec" />
                    <xforms:value ref="@kd" />
                    <xforms:label ref="@name" />
                </xforms:trigger>
            </xhtml:li>
        </xforms:itemset>
    </xhtml:ul>
</xforms:case>

one record case

<xforms:case id="onerec">

How to get a last submitted button value instead of '2' in formula [@kd=2] (i.e instead of [@kd=2] i like @kd='clicked trigger value')???

    <xforms:itemset nodeset="instance('xs')/x[@kd=2]">
        There are name "<xforms:label ref="@name" />" and id "<xforms:value ref="@kd" />"
    </xforms:itemset>

There is a back button

    <xforms:trigger>

opening the list case

                <xforms:toggle events:event="DOMActivate" case="list" />
                <xforms:label>Back</xforms:label>
            </xforms:trigger>
        </xforms:case>
    </xforms:switch>
</xhtml:body>
</xhtml:html>

Thank you


Solution

  • You could have an instance to store the index of the actually clicked trigger, like this

    <xforms:instance id="navigation">
              <data>
                <actual>1</actual>
              </data>
    </xforms:instance>
    

    Then set this index when clicking the trigger using the set-value action:

     <xforms:trigger>
        <xf:action ev:event="DOMActivate">                   
            <xforms:toggle case="onerec" />
            <xf:setvalue ref="instance('navigation')/actual" value="@kd"/>
        </xforms:action>
    
        <xforms:value ref="@kd" />
        <xforms:label ref="@name" />
     </xforms:trigger>
    

    Then, to know the active case, use instance('navigation')/actual