Date related

in repeat i want to inter date which is less than first repeat

suppose i inter 01/12/2018 in first repeat
then in second repeat date is less than this

Try this sample form:

date_check.xls (5.5 KB)

Specifically, the constraint on the date is:

if(position(..)>1, . < indexed-repeat(${date},${repeat},1), true())

which says, for every date except the first (ie position(..)>1) the date must be less than the date specified in the first repeat group (where index=1). For the first date (ie position(..)=1) the constraint is effectively made redundant by setting the result to true(), allowing you to enter any date you want the first time.

1 Like

this work for first loop but not in second

Hm. I've tested this on both Collect and Enketo, and it works as described: you may enter any date the first time, but thereafter any date entered in later instances (of the same repeat group) must be before the first date. [note, you said 'first' not 'previous'; if each date must be before the previous one, that will be a different constraint equation]. Could you please describe what you are seeing, say with an example, and confirm the behavior you desire.

Thanks sir you understand what i want each date must be before the previous one this is what i want to constraint

In that case, try this instead:

if(position(..)>1, . < indexed-repeat(${date}, ${repeat}, position(..)-1), true())

1 Like

BTW, dont forget to introduce yourself to our ODK community! :slight_smile:

it is not working in nested loop

it is not working in nested loop

Without knowing the specific structure on the form you are attempting to write, its not possible to determine why it may not be working for you. Regardless, in order to enforce the chronological order of dates entered in a form you must use a constraint, as described in my provided example. Further, if these dates occur within repeat groups, you will have to check specific dates against each other using the indexed-repeat() function, as described.

I would recommend reviewing the documentation around Referencing answers from repeated questions. If you are now using nested repeats, please read carefully the indexed-repeat() documentation about accessing sub/sub_sub parameters. Between these there should be sufficient information to help you to determine how to implement the specific constraint checking you desire.

Plz see the above file in this second loop not working properlydate_check.xls (31.5 KB)