What I’m trying to do: I have a form where the user can set a total land area that they own (say, 10 acres). A repeat group then lets them indicate how many acres they use per economic activity (say, 3 acres for farming and 7 acres for livestock). I’m trying to implement a constraint so that the sum of the individual plots cannot be greater than the total area initially indicated – see questionnaire XLSForm attached. TEST_Questionnaire.xlsx (16.8 KB)
Challenge: I cannot get the dynamic constraint to work based on the calculation because the [sum of individual plots] from the repeat group is initially empty. Does anyone have a solution for this?
Also, is it possible to implement a constraint so that within the repeat group, no select_one option is chosen more than once across the repeats?
I have a trick for your issue which is not a constraint but work like it.
kindly find attached file.
TEST_Questionnaire_Trick.xlsx (17.1 KB)
Thank you very much for trying to help! This is almost it (although the pre-defined number of repeats in the coalesce formula isn’t the most elegant, but workable).
The problem is that it apparently causes an infinite validation loop (or some other crash). How to reproduce what I mean:
- The sum of your entries in the repeat group exceeds the total area entered and multiple entries cause the excedance (the error message shows correctly on multiple repeat entries, BUT then)
- when you want to fix it by removing the last repeat entry (clicking the “-” button) and clicking “validate” again in Enketo, the form hangs itself. The validation button does this (see image):
If you know how to fix this, or find a better solution, please let me know!
I’ve fixed the previous issue and it works now as a constraint.
TEST_Questionnaire_Trick 2.xlsx (17.0 KB)
Let me know if it is fine now.
Thank you, this works great now to ensure that the sum of the items entered does not exceed (<) the available total.
Ideally I need to be able to ensure that the sum of items equals (=) the total available previously entered, since I need to know how the entire land area is used. The user shouldn’t “get away with” assigning only, say, 8 out of 10 acres.
Based on your latest example, I still can’t make this work because implementing the “equals” constraint in the repeat loop will only allow for 1 entry that exactly matches the total.
I’d be most grateful if you have an additional idea.
The only way that I’ve found is to put a constraint after the repeat group.
Kindly find the attached file.TEST_Questionnaire_Trick 2 V2.xlsx (17.1 KB)
let me know if you need any help.
Thank you, Yasser, now it works perfectly. Thank you very much for your continued help with this and for finding a solution. I highly appreciate it!!