Add Loop syntax for Calculations
- Dominant language
- CSS
- Stars
- 34
- Forks
- 28
- Avg merge
- 27m
- Merged PRs (30d)
- 1
Description
Original thread: https://groups.google.com/forum/#!topic/javarosa-developers/6Z1fSlJdb7Q):
_________________________
My organization uses ODK and would like to add a new 'module' of questions to some of our current surveys. We are using Xforms. In particular, we are writing our forms in Excel (XLS forms), and converting.
A major thing desired has been the ability to have dynamic constraints. We are struggling to think of a way out of our problem without some sort of ability to declare a 'for loop' style iteration.
Basically we want a repeat, where in each iteration we ask about the respondent's status during a particular period of time. Each repeat is a group, where there are fields for 'start date', 'end date', and 'status'.
What we would like is the ability to make sure that none of these periods are in conflict. The end date of one period cannot occur after the start date of another period. They cannot overlap. We want that when a respondent were to need to go back and change a previous response, it would be able to *iterate through the start/end dates for each response within the repeat* and check each one to make sure there is no conflict.
We think it might be nice to have syntax as would follow below.
*Desired Syntax*
`for_each([repeatName], [groupName], [fieldName], [representativeReferenceVariable], [iterator], [conditions])`
*Example*
This would be the constraint in the 'start_date' field of a repeat instance of a 'pregnancy_history' question group.
_Single Line_
`for_each(pregnancy_history_repeat, pregnancy_history_group, end_date, myRef, i, (${myRef} < .))`
_Extended_
```for_each(
pregnancy_history_repeat, pregnancy_history_group, end_date,
myRef,
i,
(${myRef} < .)
)```
So in this example above, we would be identifying our reference variable as the 'end_date' field variable within a group, within a repeat. We would then be creating an in-line reference variable 'myRef', and declaring an iterator variable ('i') if for any reason needed. For each iteration, we're comparing the 'end_date' field value of that iteration to the value entered in the current field (represented in XlsForm/Xform syntax as a ' . '), ie. the 'start_date' field. (edited)
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the linked original developer thread and the xforms-spec repository to understand the proposed loop syntax and repeat semantics. Agree on the syntax, overlap-checking behavior, and specification entry point before defining what an accepted implementation or specification update would require.
Written by the indexing model from the issue text.
Assessment
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100