B4J Question Modal Form, check if it's "dirty"

Lahksman

Active Member
Licensed User
Longtime User
Hi

I have a modal form that contains a number of settings that the user can change.
When closing this form I only want to ask the user if he wants to save his changes if there are actual changes made.
I've been trying some different approaches but can't find a solution.

How can i check if certain views (in my case textfields & colorpickers) have changes after the initial load?
 

DonManfred

Expert
Licensed User
Longtime User
Use a Map to store the values when you fill the form.
Use the view as key and the old value as value.

When saving you can check the values in the map.... and compare them to the new values..
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Another approach (valid if you want to show the dialog if any of the settings is modified, then save all of them): a boolean global variable.
When any of the current values is changed you set the global var to True. On exit, if that var is True then you show the dialog and eventually save ALL the settings.
This will fail if the user changes an item from value A to value B and later again to value A because you monitor the "change event" but not the value itself.
@DonManfred approach will work in any condition since it "stores" the original value and uses it for comparision on exit, although it takes up some more RAM (this shouldn't be a problem since probably you won't have tens of controls anyway).
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
a boolean global variable.
When any of the current values is changed
i guess this is more work than my Solution as you need to add code to any textchanged, checked_change, whatever event to do this.
although it takes up some more RAM
Only the value (text from editfield for ex.) is relevant. The object itself (using as key) is a reference. so it does not eat much ram.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Good morning @DonManfred
I supposed the OP had the "changed" events already in place, so adding a line to set a var could be a solution.
RAM: you know, I'm from the old days when even a byte counted so I find always difficult to not "pack" info and shrink everything..eheh
When downloading (I do it rarely) from the Store, reading sizes of tens of MB for what honestly are simple functions makes me uncomfortable. As I'm writing this I checked Firefox RAM usage : 286MB! And I opened only our Forum pages starting from the most recent B4J post..
 
Last edited:
Upvote 0

Lahksman

Active Member
Licensed User
Longtime User
(this shouldn't be a problem since probably you won't have tens of controls anyway)
There are about 15 controls. I've also tried the global variable approach but another downside of this is that the change is also triggered when I load the known settings. So i've tried setting the variable after my controls were loaded but then somehow the process of showing the modal form got in the way. That's probably just because I don't fully see/understand how the modal form works.

So for the ease of it, i'll give @DonManfred's solution a try.
 
  • Like
Reactions: udg
Upvote 0

udg

Expert
Licensed User
Longtime User
I too prefer @DonManfred approach. I suggested an alternative just in case you had everything already in place and because it sounds easier.
My idea was: since I've to check each control's value for validity, range checking etc, why not add a setting of a global semaphore to track that "something somewhere" changed? Anyway, since we already highlighted a few possible glitches with that solution, go with the map approach.
 
Upvote 0
Top