Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expression with absolute path is not evaluated correctly for nested repeats #246

Closed
sadiqkhoja opened this issue Nov 1, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@sadiqkhoja
Copy link
Contributor

sadiqkhoja commented Nov 1, 2024

Web Forms version and package (e.g. are you using web-forms or only the engine?)

Web Forms: v0.4.0-53-gc9a0ee3d

Browser and version

Chrome 130.0.6723.70

Device used

MacOS 14.5

Problem description

In the following Form calculate of n1 just reads the value of q1s from the first instance of root_repeat.

Steps to reproduce the problem

Form Definition
<?xml version="1.0"?>
<h:html xmlns="http://www.w3.org/2002/xforms" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jr="http://openrosa.org/javarosa" xmlns:orx="http://openrosa.org/xforms" xmlns:odk="http://www.opendatakit.org/xforms">
    <h:head>
        <h:title>joinnestedrepeat</h:title>
        <model odk:xforms-version="1.0.0">
            <instance>
                <data id="joinnestedrepeat" version="20241101142134">
                    <root_repeat jr:template="">
                        <nested jr:template="">
                            <q1/>
                        </nested>
                        <n1/>
                    </root_repeat>
                    <root_repeat>
                        <nested>
                            <q1/>
                        </nested>
                        <n1/>
                    </root_repeat>
                    <meta>
                        <instanceID/>
                    </meta>
                </data>
            </instance>
            <bind nodeset="/data/root_repeat/nested/q1" type="string"/>
            <bind nodeset="/data/root_repeat/n1" readonly="true()" type="string" calculate="join(',', /data/root_repeat[position(..)]/nested/q1)"/>
            <bind nodeset="/data/meta/instanceID" type="string" readonly="true()" jr:preload="uid"/>
        </model>
    </h:head>
    <h:body>
        <group ref="/data/root_repeat">
            <label>root_repeat</label>
            <repeat nodeset="/data/root_repeat">
                <group ref="/data/root_repeat/nested">
                    <label>nested</label>
                    <repeat nodeset="/data/root_repeat/nested">
                        <input ref="/data/root_repeat/nested/q1">
                            <label>q1</label>
                        </input>
                    </repeat>
                </group>
                <input ref="/data/root_repeat/n1">
                    <label>values of q1</label>
                </input>
            </repeat>
        </group>
    </h:body>
</h:html>

Expected behavior

Value of n1 in each repeat instance should be equal to the join of all q1s in the same instance.

Other information

If I change calculate to ../nested/q1 then it works correctly.

This could be related to #101

@github-project-automation github-project-automation bot moved this to Todo in Web Forms Nov 1, 2024
@sadiqkhoja sadiqkhoja added the bug Something isn't working label Nov 1, 2024
@lognaturel
Copy link
Member

lognaturel commented Nov 1, 2024

Whoops, just realized that this looks like expected behavior.

/data/root_repeat[position(..)] is identical to /data/root_repeat[1]. I think the intent here was /data/root_repeat[position() = position(current()/..)] (or using the shortcut syntax: /data/root_repeat[position(current()/..)])

@github-project-automation github-project-automation bot moved this from Todo to Done in Web Forms Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

No branches or pull requests

2 participants