XLSForm / pyxform

A Python package to create XForms for ODK Collect.
BSD 2-Clause "Simplified" License
77 stars 134 forks source link

Select from repeat inside that same repeat transforms choice_filter expressions with current() #504

Open lognaturel opened 3 years ago

lognaturel commented 3 years ago

Related to #503

Software and hardware versions

pyxform v1.3.3

Problem description

Select from repeat transforms choice_filter expressions with current().

Steps to reproduce the problem

Use current() in a choice_filter expression for a select from repeat inside that same repeat. Note that the behavior is correct when it's not a select from repeat or when it's a select from repeat not inside the same repeat.

    def test_explicit_choice_filter_with_current__passes_current_expression_through(self):
        xlsform_md = """
        | survey  |                      |        |         |                         |
        |         | type                 | name   | label   | choice_filter           |
        |         | select_one yes_no    | outer  | Yes?    | name = current()/../foo |
        |         | begin repeat         | repeat | Repeat  |                         |
        |         | select_one ${inner}  | dynamic| Dynamic | name = current()/../foo |
        |         | select_one yes_no    | inner  | Yes?    | name = current()/../foo |
        |         | end repeat           | repeat |         |                         |
        |         | select_one ${inner}  | dynamic| Dynamic | name = current()/../foo |
        | choices |                      |        |         |                         |
        |         | list_name            | name   | label   |                         |
        |         | yes_no               | yes    | Yes     |                         |
        |         | yes_no               | no     | No      |                         |
        """
        self.assertPyxformXform(
            name="data",
            debug=True,
            md=xlsform_md,
            xml__contains=[
                '<itemset nodeset="../../repeat[name = current()/../foo]">',
            ],
        )

Expected behavior

Expressions with current() should always be passed through.

KeynesYouDigIt commented 2 years ago

@lognaturel Would this be a good issue for me to take a crack at now? Or is anything else more pressing?

lognaturel commented 2 years ago

Thanks, @KeynesYouDigIt! I don't have a good sense of what this fix will look like. Some initial analysis to see whether there's a straightforward solution would be much appreciated. If there isn't, it might be best to leave on the back burner but having that first dive done would be very helpful.