Is it possible to limit the range of years shown in the drop-down when choosing a date?
I’m setting up a survey to collect vaccinations dates of children, and I would like the year option not to include years after current year or at least not include years up to 2069. Making the collection of data a bit easier.
Yes, this is definitely doable, and there are a couple of ways to do it.
Use a constraint: See ODK-X XLSX Converter Reference — ODK-X Docs for optional columns, including constraints and constraint messages. For example, in one of our surveys in 2018 we were collecting year of birth in variable q305_2. So we had a constraint:
(data(‘q305_2’) >= 1919 && data(‘q305_2’) <= 2018) || data(‘q305_2’) == 9998
and our message was:
Year {1919-2018, 9998 if don’t know}
You can also just do a drop down where you do a select_one and only have the valid years (if this is a few only, like you are doing vaccinations for under-5, so that they can only have been vaccinated in 2014, 2015, 2016, 2017, 2018, 2019, this is easy to just specify in choices).
If you are using a date variable (widget) you can do a constraint too, you probably just need to do some more options/math.
To my understanding the constraint solution will only limit the possible accepted inputs and still show all years if I’m using the date widget (which I am for now).
The reason we’re using the date widget, is to try to limit the possible mistakes and at the same time make the collection of data efficient. Further our assistants aren’t used to working on mobile devices that’s why the date widget with limited shown years seemed as the best solution.
I like the select_one_dropdown solution, though I would prefer to change the date widget itself, to avoid doubling my date variables.
Also the select_one_dropdown option would require manual changes in the code. I know it isn’t a big change, but we have a lot of short term employments (myself included), so we like as much as possible to be done automatic.
The date widget currently does not support changing the range. So you would need to either create a custom prompt that extends the default date widget or use select_one_dropdown
You can actually replace the date widget with select_one_dropdowns without doubling your date variables. You could make the select_one_dropdowns as session variables and use a calculate to populate the original date variable.
I seem to run into a problem, where my survey wont load if my title.text value in my choices sheet is an integer - making it difficult to make my own date dropdown.
I get the error “Error in template.”
This problem ONLY happens if I make a new value in choice_list_name and assign integers as titles. Renaming old values to integers works fine.
E.g. renaming the following: