Dynamic default within a repeat group

I'm having issues getting dynamic defaults to work within a repeat group.

This is for a time sheet form. The work flow I'd like is to have is: the enumerator selects all the staff on their crew from a select_multiple field ${crew}, then they enter a repeat group ${timesheet} that will allow them to add ${start} and ${end} times for each member of the crew they selected.

Often crew members will have the same start and end time so I'd like to have a dynamic default for these fields based on the last-entered value. I currently have ${timesheet}[position() = position(current()/..)-1/start as the default value. The issue seems to be that the repeat instances are created after the enumerator selects their crew members in the first step, before they have a chance to enter start and end times. If the enumerator selects multiple crew they will have empty start and end times. If the enumerator selects one crew member, enters start and end times, and then returns to the first step to select another crew member, the default values for the second time sheet are correct.

I'd like to avoid using a trigger as I don't want calculated values to overwrite modified values.

Is this even possible or should I come up with a different work flow?

Did you try with once(..) in the calculation?

It looks like you're following the example at https://docs.getodk.org/form-logic/#dynamic-defaults-in-repeats? What I think might be going on is that you're also using repeat_count which you're right, means that repeat instances are created before the first date is set.

@wroos's suggestion of a calculation with once would mean all repeat instances get the same default value because the update would cascade. That doesn't feel like quite what you want. I think your best bet is a trigger but that would only work if you're pretty sure that users won't move backwards to change dates for previous repeat instances. Otherwise you either have to rethink the repeat_count or the default.

1 Like