Collect: When exiting a form, only prompt to save changes if unsaved changes exist

Created on 19 Feb 2018  路  27Comments  路  Source: getodk/collect

Software and hardware versions
Tested on Android 8.0 on One plus 5T

Problem description
Although no changes are made in the form, it always asks to save any change or delete any change after pressing back key to exit the current form.

Expected behavior
It should be such that if any changes are made in the form then only it should ask to save any changes made or to discard them.

Steps to reproduce the problem

  1. Replicate the current form whenever opened.
  2. Let user make changes if he/she wants
  3. Compare the edited form with the replicated form every time when back key is pressed to exit the form.
  4. If any difference is observed, then a pop-up dialog box asking to save the changes should appear. (It should be taken care of that when a form is only opened and then closed without any changes then no dialogue box should appear)
  5. At last, the replicated form should be destroyed to free up space.

Want to work on the issue?
Yes

help wanted

All 27 comments

Please go ahead @harsh-2711.

Please claim the issue by commenting with @opendatakit-bot claim.

Done

@harsh-2711 you will need to add a comment with the text @opendatakit-bot claim and then accept the invitation you get by email.

@opendatakit-bot claim

Welcome to Open Data Kit, @harsh-2711! We just sent you an invite to collaborate on this repository at https://github.com/opendatakit/collect/invitations. Please accept this invite in order to claim this issue and begin a fun and rewarding experience contributing to Open Data Kit!

Here are some tips to get you off to a good start:

  • Please read the README.md and CONTRIBUTING.md in this repo. Those two documents have much of what you need to get started.
  • Join the ODK developer Slack to get help, chat about this issue, and meet the other developers.
  • Sign up and introduce yourself on the ODK community forum to meet the broader ODK community.

See you on the other side (that is, the pull request side)!

@lognaturel Can u please provide me with proper resources for solving this problem as I am not able to link the classes in the project

Hello @harsh-2711, you have been unassigned from this issue because you have not updated this issue or any referenced pull requests for over 10 days.

You can reclaim this issue or claim any other issue by commenting @opendatakit-bot claim on that issue.

Thanks for your contributions, and hope to see you again soon!

It鈥檚 a tiny improvement but needs efforts if you want to solve this issue thoroughly.
Here are some opinions of my own:

  1. Comparing the .xml files (saved instances) with instance in memory when back-button pressed ,if file changed then we can pop up the dialog.
  2. Checking the hash codes in data-object ,if data changed in memory during the edition ,we can pop up the dialog.
  3. Listening the input-actions of users during the edition and deciding whether to pop up the dialog.

After viewing the code of data-exporting and JavaRosa, I think it鈥檚 almost impossible to address this issue with a small change. It costs too much memory when we comparing files and listening actions.We don't worth to do these,but we can find another approach to improve this, although it cannot meet all your requirements.We can listen whether users have pressed the save button or not and decide if it鈥檚 necessary to show the prompt, when users just pressed the back button we show prompt every time.

Hope that can help!

Hello @huangyz0918, it looks like you've currently claimed 1 issue in this repository. We encourage new contributors to focus their efforts on at most 1 issue at a time, so please complete your work on your other claimed issues before trying to claim this issue again.

We look forward to your valuable contributions!

Hello @huangyz0918, it looks like you've currently claimed 1 issue in this repository. We encourage new contributors to focus their efforts on at most 1 issue at a time, so please complete your work on your other claimed issues before trying to claim this issue again.

We look forward to your valuable contributions!

@opendatakit-bot claim

Hello @edyasikpo, it looks like you've currently claimed 1 issue in this repository. We encourage new contributors to focus their efforts on at most 1 issue at a time, so please complete your work on your other claimed issues before trying to claim this issue again.

We look forward to your valuable contributions!

@opendatakit-bot claim

Hello @jd-alexander, it looks like you've currently claimed 1 issue in this repository. We encourage new contributors to focus their efforts on at most 1 issue at a time, so please complete your work on your other claimed issues before trying to claim this issue again.

We look forward to your valuable contributions!

@huangyz0918 You have made some pretty good points about the approaches that can be taken for this. I have been tinkering around with a possible solution and it's working so far. I basically monitor calls being made to save forms and I also do checks to see if answers or null or not. The only edge case I haven't covered is the ability to detect if a question has an initial/default answer and disregard it when the user presses back because right now if a default answer is spotted by solution displays the dialog.

@lognaturel What do you think would be the proposed method for detecting if a dialog should be shown or not. 1) Should it be determined by monitoring when the user triggers a save action on any of the form screens and if they do then the dialog should be shown or 2) should it be shown if there have been no changes to the answers?

@jd-alexander Sounds great! But as my understanding, you know, if user wants to edit the saved form, most of the forms have a saved value (initial value?), is the way still working? Besides, if the user edited the form after he pressed the "save" button in the toolbar, will the dialog appear ?

Maybe you can try --force to claim this issue, good luck :+1:

@opendatakit-bot claim --force

Hello @jd-alexander, it looks like you've currently claimed 1 issue in this repository. We encourage new contributors to focus their efforts on at most 1 issue at a time, so please complete your work on your other claimed issues before trying to claim this issue again.

We look forward to your valuable contributions!

@huangyz0918 oh yes indeed! I think that's exactly what would take place so that approach wouldn't work as well. So it seems the only approach to this will be to build out a mechanism to track changes of answers once the form has loaded.

The force claim isn't working so I will wait until the other issue I submitted has been accepted before claiming again.

@jd-alexander Thanks for looking at this! This change was first discussed last year in #569. I was not sold on it then and I must say I'm still not so sure about it. As @huangyz0918 has identified and you've confirmed, this is tricky to do well and the payoff is low. There has been no user complaint about the existing behavior -- I think it's something that developers notice when they're playing around with the app but that's not actually a problem for users.

Do you see a straightforward way to track changes across all question types?

One approach that could be taken is to have a isDirty flag as a property of QuestionWidget that's triggered when an answer is set. This would require that setters are enforced on all question types though so it might be a bit invasive as many questions would have to be changed.

That sounds about right for a minimal change. Even then, I think you'd have to do something additional for the case where the user is on a question and has made a change to an answer without swiping and then taps back (the setter would presumably not yet have been called in that case). I think field-lists are also a challenge -- a change to any of the answers on the current screen has to be detected.

I don't think this is worth it. Do any others feel strongly one way or the other?

Agreed that this is a lot of work for a fairly minor feature. I propose we close this for now.

I don't think any flag would work in this case. Consider a case when you open a saved form with one question (null answer) then you answer that question and eventually remove the response.

One possible solution would be to keep an original answer and a temporary one and during saving comparing them.

The second possible solution would be using md5 hashes as @huangyz0918 already noticed but probably it would require more effort (we would need to save an instance to a separate file -> compare with the original instance and the decide what should be done.

While my first idea isn't super easy as well and would require changes on the Javarosa's side.

Thank you all for the thoughts on this issue. Let's close for now. If a user with data collectors in the field has a strong reason for why this might be a problem we can reopen.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DreamyPhobic picture DreamyPhobic  路  4Comments

seadowg picture seadowg  路  4Comments

yanokwa picture yanokwa  路  4Comments

rcovane picture rcovane  路  3Comments

kkrawczyk123 picture kkrawczyk123  路  3Comments