1. What is the issue? Please be detailed.
Is there a way to get Enketo to trigger validation when a field is set to a default by a trigger?
I'm running ODK Central self-hosted on AWS.
versions:
e4221ebeb41cd6ccb0cedad0461e5b603c207339 (v2024.3.2-1-ge4221eb)
8b1de6512faa7a60c05764312caec01f5c138c42 client (v2024.3.2)
7574030f7ea8750f3837950001a5efcdeba45b92 server (v2024.3.1)
I'm hosting an ODK Form via a public submission link and I expect nearly all submissions to come from a browser via the Enketo webform. So far, it works absolutely beautifully.
The XLSForm has one field for a default date, and several groups of other fields which prefill that default date when a third field is clicked.
There are several of these prefilled fields, and most have their own date range limits, so I'd like to nudge our users to adjust the date ranges to the available limits (which I also show in the form as note).
What works well: when submitting / validating, the fields display their validation error messages.
What I would love to see is that constraints are evaluated when fields are set to defaults via a trigger.
This would mean that users see any errors as they go through the form and don't have to scroll back after trying to submit (and feel bad about having filled in the form incorrectly).
The salient fields are:
# Field 1: The default date
date ds_default_start_date Default start date The default start date for any requested dataset unless specified differently for a requested dataset.
# Field 2: The checkbox which decides whether field 3 is shown & populated or not
select_one yes_no ds_doc_notifications_requested Include this dataset? This dataset is Event based. Data is available from 1977. yes no
# Field 3: A date that is set to the date of field 1 if field 2 selects "yes"
date ds_doc_notifications_start_date Start date The earliest date of event to include
required: ${ds_doc_notifications_requested} = 'yes'
relevant: ${ds_doc_notifications_requested} = 'yes'
constraint: . >= date('1977-01-01')
constraint_message: Please select a start date from 1977 onwards.
calculation: ${ds_default_start_date}
trigger: ${ds_doc_notifications_requested}
2. What steps can we take to reproduce this issue?
If helpful, I will create a MVE. For now, I'm curious whether others have experienced the same issue.
When filling in the form on ODK Collect, the validation is triggered on swiping to the next screen, and the validation message shows up (and the layout is of course absolutely stunning).
Because the form is loaded in its entirety in Enketo, the "moving to next screen" event is of course missing.
3. What have you tried to fix the issue?
Via form design: I should improve the default a calculation so that e.g. my field 3 (populated with date from field 1) is the latest date (max()?) out of field 1 default date and my "earliest_available_date".
So this formula works by avoiding any validation errors happening through the trigger default:
if(${ds_default_start_date}<date('1971-01-01'),date('1971-01-01'),${ds_default_start_date})
if(default_date < earliest_available_date, earliest_available_date, default_date)
(The user could still update this value by hand and enter an invalid value, which then will raise the constraint message on submission. Fine by me.)
But this does not address the issue, which could be a limitation of Enketo, so I would like to suggest this to be considered for the upcoming ODK webforms.
Edit: I missed that Enketo has a "pages" mode https://xlsform.org/en/#multiple-webpage-forms which likely evaluates constraints on navigating to the next form page.
4. Upload any forms or screenshots you can share publicly below.
I can send the XLSForm as is via DM or upload a simplified MVE.