-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remembering previously entered values (auto-fill) #2882
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything is looking great. I have some comments about the general design of the changes this PR introduces, but nothing that should block the PR, IMO.
Before merging, I think other users with more experience with the codebase should review the PR as well.
collect_app/src/main/java/org/odk/collect/android/tasks/FormLoaderTask.java
Outdated
Show resolved
Hide resolved
collect_app/src/main/java/org/odk/collect/android/tasks/FormLoaderTask.java
Outdated
Show resolved
Hide resolved
collect_app/src/main/java/org/odk/collect/android/provider/FormsProvider.java
Outdated
Show resolved
Hide resolved
@opendatakit-bot label "needs review" |
collect_app/src/main/java/org/odk/collect/android/tasks/SaveToDiskTask.java
Show resolved
Hide resolved
collect_app/src/main/java/org/odk/collect/android/utilities/FileUtils.java
Show resolved
Hide resolved
collect_app/src/main/java/org/odk/collect/android/upload/InstanceGoogleSheetsUploader.java
Outdated
Show resolved
Hide resolved
Nice and simple solution! LGTM! |
@grzesiek2010 I think this is probably ready for testing. Can you do a review and tag it for testing when you're satisfied? |
@cooperka Can you remove the empty commit so we have a cleaner commit history? You should be able to do the rebuild from your CircleCI account. |
I tried the form you attached and got this:
it's because I just copied the xml file not creating -media dir. I know that if we download a file from aggregate a dir is created automatically but this case should be handled better. Our users can create their own servers which don't do that. |
@grzesiek2010 I added a generic fix in |
@grzesiek2010 fixed. The file will always exist now before the form is parsed, even if it's later deleted. @opendatakit-bot label "needs review" |
I believe this means that a plain-text copy of the latest filled instance will always be available, even in the case of an encrypted form, is that right? If so, perhaps the caching shouldn't happen in the case of an encrypted form? I only took a quick look at the JR pull request and didn't immediately see whether the last saved XML is always parsed or only if the blank form queries it (as discussed in the spec thread). Either way, I think it would be good to have a record of a performance check with a big form and big filled instance. |
Good catch @lognaturel, last-saved instances should definitely be disabled (or encrypted) for encrypted forms. I think I'll go the easy route of disabling it unless you think it would be trivial to support encrypted last-saved instances (I haven't dealt with ODK encryption before). The last-saved instance |
The idea with ODK encryption is that access to the device can't compromise access to the data at all. In practice, that means asymmetric encryption with the private key never getting close to the device. So certainly that scheme wouldn't allow for querying the last-saved instance. I think disabling for encrypted form sounds great. |
It will always be deleted on save if finalized, along with the rest of the plaintext files. Because of this, InstanceSyncTask doesn't need to delete it (nor does it even know of its existence because it's in a separate directory) so it just passes in `null`.
I modified this XLS to have over 1000 unique text fields, all with different default values. Here's the final XML with the I executed For what it's worth, the main |
I think that the solution for encrypted forms with removing |
I agree that it's not 100% ideal for encrypted forms, but I can't think of a better alternative that's simple enough to be worth implementing, verifying, and maintaining. I personally favor security over ease of use in this case. As described on the XLSForm spec:
I think if someone wants to use last-saved on an encrypted form, they're welcome to, but they should simply do so before finalizing anything. If you have a simple proposal that would keep things secure while also allowing for more intuitive last-saved behavior feel free to suggest! |
Yes, it would be difficult to handle this case. Ok so maybe let's leave it as is but this case should be described in the doc. Please keep it in mind creating an issue. |
@lognaturel if you can't see anything else we should improve please add |
@cooperka, I do not completely understand why the form which I could use for testing has been removed and form which I cannot use was attached in the comment. Not very tester friendy :( It took me a long long time to change All widgets form so I could use it for testing. |
@kkrawczyk123 thanks! |
Sorry about the form being removed @kkrawczyk123, looks like GitHub may have deleted the file because it was uploaded to my fork. Thank you for uploading your own. This feature is mainly intended for text-based widgets, though as you mentioned some other widgets also work. I'll make this clear in the upcoming documentation. Thanks! |
Merge away, @grzesiek2010! So sorry you rebuilt the form, @kkrawczyk123! If that happens again, do ask in Slack or a comment to see if someone has a copy! |
Closes getodk/roadmap#30
Depends on getodk/javarosa#406(merged and snapshotted)Allows form designers to refer to the last-saved instance of this particular form in order to retrieve answers from it. Currently intended for text-based answers rather than media. Simply add an external instance to your form:
The instance
id
can be anything you want.Then you can access the external data as usual, for example:
xforms-ready
is being deprecated, see here for more info. TL;DR: Useodk-model-first-load
now instead.What has been done to verify that this works as intended?
Extensive testing with modified All Widgets.xml: filling blank forms, saving forms, filling new blank forms, finalizing, exiting without saving, etc.
Addtional testing with encryption to verify
last-saved.xml
is deleted when the form is finalized. Valid sample encryption key you can test with:Why is this the best possible solution? Were any other approaches considered?
See extensive discussion at getodk/roadmap#30. The result of the discussion there was this approach. It makes use of existing logic to accomplish this feature without needing too much new code.
Collect caches the last-saved instance to the form's media directory
formName-media/last-saved.xml
on each save. This file will stay around even if the original saved instance is lost, which is probably what users would expect. The form's media directory is deleted when the blank form is deleted from the device, which is also probably what users would expect.When parsing new FormDefs,
lastSavedSrc
will be passed to JavaRosa as either"jr://file/last-saved.xml"
ornull
if no file exists because the form has never been saved. Anull
value means no instancesrc
is provided, meaning the instance will be treated as internal instead of external. The internal<instance id="last-saved"/>
has no children and thus will provide empty values for anything referring to it.How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?
Form designers will be able to designate questions as "auto-filled" based on the last-saved value for that particular question. I don't anticipate much regression risk here since the old logic isn't significantly modified.
Do we need any specific form for testing your changes? If so, please attach one.
Linked above.
Does this change require updates to documentation? If so, please file an issue here and include the link below.
Yes [TODO file issue].
It will also require an update to ODK Build if they want to support this [TODO file issue].
Before submitting this PR, please make sure you have:
./gradlew checkAll
and confirmed all checks still pass OR confirm CircleCI build passes and run./gradlew connectedDebugAndroidTest
locally.