When are expressions in a form recomputed?

No, exit without save does nothing.

That's correct.

Load is always a full recomputation. Save and finalization are identical to each other. There is some complexity around what exactly is recomputed then that I don't know off the top of my head. I don't believe we have worked in that logic since I've been part of the project. If there's a specific form or behavior you want more details on, it would be helpful to start with that.

Correct, calculations are done even for non-relevant fields and are ready to be displayed as soon the fields become relevant. However, non-relevant fields always evaluate to blank (that's what the alignment between Enketo and Collect was about).

It's kind of the other way around. "Triggers" (e.g. https://docs.getodk.org/form-logic/#dynamic-defaults-from-form-data) are computed separately, only when the triggering expression changes. All other expressions may be recomputed at any time. In practice, the engines do try to limit recomputation as much as possible but I think the most useful mental model to have is that any expression could be re-evaluated at any time. If that's not desirable, a "trigger" or if or once should be used.

Sorry, I'm not using entirely consistent language. I don't intend to mean anything different between recomputation and recalculation. required and constraint are a bit different than calculates and relevance because they don't cascade. That is, they can't be used in further expressions and they only are related to exactly one field. That means engines can limit when they recompute them. My recollection is that Collect uses this knowledge to only evaluate when exiting the current screen when only one question is displayed.

Again, I think the general mental model to have is that every expression can be reevaluated at any time, except when using a "trigger". If there's specific behavior that doesn't feel right or that is different between Collect and Enketo, we should dig into those specifics.

1 Like