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 first repeat instance(s) for jr:choice-name choices #758
Conversation
@@ -16,6 +16,25 @@ | |||
|
|||
package org.javarosa.core.model; | |||
|
|||
import static java.util.Collections.emptyList; |
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.
I think I'm likely the one who messed up this order previously. 😬 My IDE should now enforce the order that's mostly consistent across existing files.
@@ -117,4 +119,75 @@ public class ChoiceNameTest { | |||
scenario.answer("/data/city", "grenoble"); | |||
assertThat(scenario.answerOf("/data/city_name"), is(stringAnswer("Grenoble"))); | |||
} | |||
|
|||
@Test public void choiceNameCallWithIndexedRepeatAndStaticChoices_worksWithMultipleRepeats() throws IOException, XFormParser.ParseException { |
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.
This is not affected by the code change. It's there to document behavior that has always worked.
// SurveyCTO: We need a absolute "ref" to populate the dynamic choices, | ||
// like we do when we populate those at FormEntryPrompt (line 251). | ||
// The "ref" here is ambiguous, so we need to make it concrete first. | ||
// ref, the reference used to specify where choices are defined, could be an absolute |
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.
This IFunctionHandler
implementation should be moved out to another file now we're touching it again.
Closes #757
What has been done to verify that this works as intended?
Added tests
Why is this the best possible solution? Were any other approaches considered?
My initial instinct was that using a reference to a repeat nodeset rather than a specific repeat instance to specify where choices should be taken from is a form design issue. But then I realized that a standards-compliant XPath engine would use the first repeat instance(s) when given a nodeset reference where it needs a single node reference.
This doesn't work well with choice filters but I think that's ok because it also wouldn't have been possible before. My priority here is to ensure that XLSForms that used to work continue to work without modification.
My recommendation for writing these kinds of
choice-name
calls would be to make them relative from within the repeat instance rather than making it from outside.How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?
This only affects
choice-name
calls given a reference parameter that is a nodeset reference. I think the case in the test is the only one in which this kind of reference would make sense. There's also the analogous nested case and that's why there's a for loop to qualify every unboud reference level.Do we need any specific form for testing your changes? If so, please attach one.
https://docs.google.com/spreadsheets/d/1MZvF9ynsOdGMWeZF8YsjuoUK9E0t83LZMi5-RsBOEiI/edit#gid=1068911091
Does this change require updates to documentation? If so, please file an issue here and include the link below.
No.