-
Notifications
You must be signed in to change notification settings - Fork 137
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
Use relative references for repeats only. #187
Conversation
OMG, this is exciting! 👍 Maybe we can take out that deviation from the spec some time. Will check it out! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The number of steps down ( current()/../ vs current()/../../../../) should be determined from the context (i.e. question where ref is used). See https://docs.google.com/spreadsheets/d/1DUgtclTL8fBOHS9h88a8eC6x1u5M17g1b7CPJBm7JP4/edit?usp=sharing.
You could decide to strip the current()/
part if the expression is not inside a predicate, e.g. calculate="../crop"
instead of calculate="current()/../crop"
. That would be preferable. See https://docs.google.com/spreadsheets/d/1lTJ9-AnrGDdFK8UzvmSglqFgGjLsdzQzp_XLoYkV__Q/edit?usp=sharing
P.S. Gotta run now, but will markdownify these forms, to facilitate turning them into tests later.
As the thread @ukanga links to notes, Javarosa doesn't interpret <select1 ref="/repeat-relative-current-1/rep/sel_a">
<label> Verify <output value=" current()/../crop "/> </label>
<itemset nodeset="instance('crop_list')/root/item[name = current()/crop ]">
<value ref="name"/>
<label ref="jr:itext(itextId)"/>
</itemset>
</select1>
<group ref="/repeat-relative-current-1/rep/group">
<select1 ref="/repeat-relative-current-1/rep/group/sel_b">
<label> Verify <output value=" current()/../../crop "/> </label>
<itemset nodeset="instance('crop_list')/root/item[name = current()/../crop]">
<value ref="name"/>
<label ref="jr:itext(itextId)"/>
</itemset>
</select1>
</group> Perhaps there can be some flags or model version information added in somehow as explored in the thread but I don't think it can be the default behavior for pyxform right now, at least not for choice filters. The problem is that even if we patch JR today (which doesn't sound trivial), all users running older versions of Collect (and there are many), will be unable to use new forms with choice filters. That's what the very long thread was about. |
Ah, yes, when fixing the current() bug in JR, I understand you may need a way to determine whether an (old) XForm may be relying on a bug-dependent usage of current(). (UPDATE: made my comment less nasty (sorry) and moved useful parts here: getodk/javarosa#293) |
Test 1:
expected output for b itemset: Test 2:
expected output for a bind: |
These tests look great. Would be good to get to a high-level game plan also. Can we do relative paths everywhere other than choice filters for now? Do we wait on the overall change? |
I'm fine with just introducing them all at once (waiting a bit for the JR folks) or in 2 batches (splitting choice_name and rest). Whatever is easiest in terms of pyxform code changes. What is important to me is to not lose momentum in getting the code ready to go now that this is hot (after 5 years). Merging can wait. |
2af622a
to
31d3fc4
Compare
Thank you guys for the comments and tests, I will add them in the next iteration on this PR. |
88ff9db
to
6e60fe7
Compare
Example of XForm XML with relative paths as generated by this PR. The first two are the examples @MartijnR provided above.
If you have the chance to test the above XML in ODK Collect or Enketo, let me know what's not working as expected. |
Everything works as expected in Collect other than the choice filters. 🎉 I think we will have a fix for JavaRosa soon. I /think/ this is actually ok to merge though I'd like a sanity check on my thinking. The JavaRosa problem is that
It's cool and powerful but there's no XLSForm support for itemsets from arbitrary nodes (#38) and it's pretty esoteric. I've only shown users how to do it with absolute paths but have never seen it come up with relative paths before. The other case is choice filters. XLSForms with choice filters in repeats fail today because an absolute path doesn't make sense there. Currently in Collect we get an error about needing The change we're going to make in JR would only affect users who are trying to use If someone else who uses Collect and understands the JR issue can run through this reasoning and validate it, I'd be comfortable merging. |
I would be in favor of this. |
Thanks. I can confirm the forms work in Enketo too. (after correcting calculation in calculate_w_relative_paths.xml to I agree it is best to avoid using current() when it's not required. |
Hi! Just wanted to drop by and say that @lognaturel's reasoning looks good to me. I also agree that I would prefer having |
Thank you all for your feedback, I will incorporate it and ping you again for another review. |
9d3ebf6
to
bc5cc42
Compare
feace66
to
4eb88d7
Compare
@MartijnR @lognaturel not sure what was pending on this but I see most of what was on your comments was addressed. Any blocker to getting this merged? |
pyxform/tests_v1/test_repeat.py
Outdated
""", # noqa pylint: disable=line-too-long | ||
xml__contains=[ | ||
"""<itemset nodeset="instance('crop_list')/root/item[name = ../crop ]">""", # noqa pylint: disable=line-too-long | ||
"""<itemset nodeset="instance('crop_list')/root/item[name = ../../crop ]">""", # noqa pylint: disable=line-too-long |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're using a predicate here, and we are changing the context to instance('crop_list')
, so we would need current() here: [name = current()/../crop]
and [name = current()/../../crop]
Thanks! Once current() is back in choice-filters, I'll run the test forms in Enketo for a final/proper check. |
I got some XForms consulting time with @lognaturel and this PR looks like what she wanted. That is pyxform generates relative paths with |
Will do a check with some forms today.
I believe all those would be hand-coded combinations of pure XPath mixed with ${shortcuts} such as a calculate that searches for a value:
Since this is so advanced, I think we can for now require those users to take care of using |
I confirm that this works great! Thanks! I noticed that the calculations in Test 2 that I provided ( |
This introduces relative referencing for
${variables}
in repeat sections.Not sure if my interpretation is accurate, I found a super long old thread in ODK forum, not sure if it is relevant still.
I picked the option of dealing with https://opendatakit.github.io/xforms-spec/#a-big-deviation-with-xforms hoping it does address it.
Fix #4