I am not sure I fully understand the question, butā¦ required and read_only are two independent settings that may be applied to any form control. And there is nothing to prevent the form writer from misusing them in combination to create a form that cannot be submitted [much like there is nothing to prevent a form writer from adding a constraint that can never be trueā¦].
Also a variable/question with read_only appearance can be set to required = true.
When is this recommended?
What is the internal difference, i.e. calculation timing?
I cant think of a usecase where this is useful. Presenting a question the user cannot ever answer, but making it mandatory, rather seems a bit cruel and inhumaneā¦
Whether the read-only or required XPath expression is evauated first is not prescribed by the XForms spec AFAIK, so this is an implementation detail. So long as the final outcome is the same: ie questions where read-only (currently) evaluates to true cannot change the associated data (as referenced by the associated XForms binding between the UI element and instance data), and the entire form cannot be submitted if any bindings where required evaluates is true have a null value.
When does it make sense to set a calculate type to required (true)?
Unless the calculation can potentially generate null (!?) there wouldnāt be any situation when the calculated result would be null, hence setting its required=true would be redundant (it will always have a non-null value) but not otherwise harmful.
Hello @Xiphware,
Thanks for the quick and detailed reply!
Use case example:
We used the following in a HH member repeat loop to make sure that the first person is the head, but allowing to select the relationship for all other members
type: select_one Relationship name: RelationHHM
label: What is the RELATIONSHIP of ${NameHHM} to the Head of Household? required: true (as we need this for all HH members) read_only: if(${LineHHM} = 1, true(), false())
calculation: once( if(${LineHHM} = 1, ā1ā, āā) ).
Choice_List Relationship
ā¦
I is working fine in ODK Collect. (But Enketo still seems not supporting dynamic read_only).
Did we get it well, please? The calculation does NOT fire differently, e.g. at different events, if the field (or a calculate) is set to required. Same if read_only.