Skip to content
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

isDirty flag #58

Open
justdan0227 opened this issue Jul 15, 2021 · 17 comments
Open

isDirty flag #58

justdan0227 opened this issue Jul 15, 2021 · 17 comments

Comments

@justdan0227
Copy link

Is there a concept of if a form is "dirty" (has been edited) vs just displayed that you can check when someone presses a back key to see if anything has been updated?

@neoneye
Copy link
Owner

neoneye commented Jul 16, 2021

There is currently no such thing. It seems like a useful idea. How would you want it to work?

@gw-dkardell
Copy link

The flag would be set to false unless one of the items in the form was updated. Then it would be set to true and then optionally an array of FormItems that are "dirty"

@neoneye
Copy link
Owner

neoneye commented Jul 21, 2021

when should the dirty flag be cleared?

@justdan0227
Copy link
Author

when the form is first loaded.. All of the dirty properties of each item is cleared. Once a form item has been updated the dirty property for the item is set to true. There should also be a call the resets all of the dirty properties to clear (once a db has been updated). Thoughts?

@neoneye
Copy link
Owner

neoneye commented Jul 22, 2021

Thoughts

For subclasses of CustomCell, should these also keep track of isDirty?

If a child viewcontroller is presented, should it propagate isDirty up to the parent?

It seems doable. However I think it's dangerous to assume that the UI keeps the correct state of the data model, so the state may get out of sync if users aren't careful. Maybe it's an antipattern.

@justdan0227
Copy link
Author

Hmmm good point.. let me think about that today. When you call validateAndReloadUI does the view not keep the state? I have the object that is used to set the initial values, I could read them all and do the comparison myself, just didn't know if a flag could work

@justdan0227
Copy link
Author

Thoughts?

@neoneye
Copy link
Owner

neoneye commented Jul 28, 2021

Do you want to discuss this via FaceTime/Signal. +45 27592923

@justdan0227
Copy link
Author

we could .. let me carve out some time that works with our timezones

@justdan0227
Copy link
Author

hey @neoneye sorry I've. been away.. crazy two weeks here. I think I have an idea that I'm going to look in the code. You have a value object for every form item. My suggestion is to have a originalValue field that is set when the form gets loaded initially. Then at an time isDirty() is called, the form enumerates the formitems and does a simple comparison against the current value and original value. Anytime there is not an exact match, the function returns false.

@neoneye
Copy link
Owner

neoneye commented Aug 27, 2021

Sorry, I'm still not sure exactly how you want it to be like. I am familiar with using dirty flags, and have been doing in the past, so it's not that I don't know about it.

Can you make some example code of how you want it to be like?

@justdan0227
Copy link
Author

Sure..

so if I have 3 form items
TextFormItem1
TextFormItem2
TextFormItem3

and I don't change any of the values in those 3; when I call isDirty, the return would be false.

if I update the value that is at TextFormItem1 and call isDirty, the return would be true and optionally provide the id's of what TextFormItems have been updated.

This way I can present a form and if the user does not change anything and presses back I can allow it. If I check isDirty and it returns true, then I can prompt the user that changes have been made to the form and ask them if they want to commit.

@justdan0227
Copy link
Author

So I finally have time to get back to this. I'll update the code I just need to understand what "innerValue" is. Is there a concept in the model that has the original value vs what is currently in that field?

@neoneye
Copy link
Owner

neoneye commented Sep 30, 2021

The TextFieldFormItem.swift has a value and an innerValue. The value is a public getter/setter that hides all the reloading of the UI. The innerValue depends on what kind of UI control it is.

The innerValue may not be in sync with what is shown in the UI. This depends on when the UI control decides to notify it's listeners. For UITextField/UITextView/UIButton I think it's always in sync.

@justdan0227
Copy link
Author

justdan0227 commented Sep 30, 2021

so I think I'm going to add a new property then along the lines of INITIAL value. Then create a new function isDirty() that will do much the same that validation does with the exception that it will do a check to see if the value that is in innerValue is different than that of the INITIAL value

@neoneye
Copy link
Owner

neoneye commented Sep 30, 2021

Cool. Looking forward to see what you come up with.

@justdan0227
Copy link
Author

Ok going to work on this over the holidays. I'm going to try and add a propertyof "original value" and then compare that when isDirty is called with the current contents..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants