Obtain a custom value based on other values in the form during the data entry session.
Update calculations/contraints/relevants/required evaluations based on the random value change.
Implementation discussed so far:
Use external data mechanism to obtain document with random value, e.g. an instance with a fixed random id attribute.
Use a question to store the random value. A change in that value would automatically trigger the resulting form engine updates. This can be a readonly question with a calculation that obtains the value from the instance e.g. instance('random')/data/thevalue
Use a button in that question (a custom OC widget with a random appearance e.g.) to re-fresh the external data document (asynchronously!), and then update the calculation in that question.
Use a custom bind attribute on the question to pass field names that should be used in the randomization, e.g. oc:params="field1, field2, field3".
OC would use the field names in the previous point to craft a URL to be published in the manifest
The URL (API endpoint) would use the auto-saved values in the randomization.
Potential issues:
asynchronous fieldsubmissions, and asynchronous data refresh may cause issues. Eg. a fieldsubmission for field1 could still be pending at the time the user requests the random value. Similarly, a request for a random value could still be pending when the Complete button is clicked.
random values could be recalculated (at any time), so good to use once() for this, and serve empty external data documents if there isn't enough information to create a random value (e.g. an empty form is loaded).
some potential XLSForm syntax issues, e.g. if a form is created with two similar random questions but with different parameters (though could be caught in enketo-validate). It would be much better if the parameters could be added to the <instance> to avoid this.
A parameter field cannot live inside a repeat, I think
earlier issue: https://github.com/kobotoolbox/enketo-express/issues/553
Requirements:
Implementation discussed so far:
random
id attribute.instance('random')/data/thevalue
random
appearance e.g.) to re-fresh the external data document (asynchronously!), and then update the calculation in that question.oc:params="field1, field2, field3"
.Potential issues:
field1
could still be pending at the time the user requests the random value. Similarly, a request for a random value could still be pending when the Complete button is clicked.once()
for this, and serve empty external data documents if there isn't enough information to create a random value (e.g. an empty form is loaded).<instance>
to avoid this.