I’m using Data Logic and the Data Gathering App Task to create my user interfaces.
Here’s my problem: I have a form where some fields depend on other fields. For example, my address forms have a field for 'State', but only addresses with the 'Country' field set to 'United States of America' need to show it.
The issue is that, if 'State' is already filled in, e.g. with 'Arizona', and the user then selects a different country than 'United States of America', the 'State' field is hidden. At this point, my address contains a wrong value in the 'State' field, and there is no way for this field to be cleared, so I may end up with an address where 'Country' is set, e.g. to 'Switzerland' and 'State' set to 'Arizona'.
How can I clear the 'State' field when the user changes the 'Country' field from 'United States of America' to a different country, e.g 'Switzerland'?
First, don’t clear the 'State' field when the user changes the country. Instead, leave it set to 'Arizona'. Make sure any Data Rules for the 'State' field are not enabled when the field is hidden.
Next, in your Process, add a step after the Data Gathering step that clears out orphaned values. At the moment, this requires duplicating some of the logic expressed in Sentries in order to determine which fields are hidden, and can be safely cleared. We're currently investigating options for improving the developer experience.
The reason for this is that clearing the 'State' value while you’re still in the Data Gathering step results in a user experience where, from the user’s point of view, data is seemingly destroyed at random, and the order in which data is filled in suddenly becomes relevant.
Imagine that the user fills in the 'State' field, then accidentally changes the 'Country', and immediately changes 'Country' back to 'United States of America'. At this point, if you clear the 'State' field when 'Country' changes away from 'United States of America', you have silently destroyed data the user has already entered.
This is a common issue in these kinds of user interfaces. For example, in this article (in German), the author points out that if [the user] enters the answers in the wrong order, previous answers are deleted again. This is an incredibly frustrating experience.
If you instead leave this data intact while the user is still in the Data Gathering App Task, no action the user takes will ever inadvertently destroy any data. Once the user leaves the Data Gathering App Task, you can then safely clean up any orphaned data.