svelte-forms icon indicating copy to clipboard operation
svelte-forms copied to clipboard

[REQUEST] Mark as no longer dirty when a field returns to its original value

Open bterrio opened this issue 3 years ago • 3 comments

Is your feature request related to a problem? Please describe.

If, for example, a field representing a checkbox has its value change from true to false, back to true again, I'd like to end up with dirty = false for that field. In that case, submitting or resetting the form wouldn't change anything, so I'd like to know to keep those operations disabled.

Describe the solution you'd like

Is there perhaps already an option for this behavior, or a workaround?

bterrio avatar Feb 10 '22 23:02 bterrio

Hi @bterrio,

Today, we do not do any value equality in the code and we don't want to do so because it might be difficult for some edge cases (e.g complex objects). The field is mark dirty as soon as its value changed once no matter if the value comes back to its original value. Meaning: the user changed the value at least once.

However, there is a reset function the is reset the value of your field to its original one and also set the dirty property back to false.

chainlist avatar Feb 11 '22 00:02 chainlist

Thanks for answering @chainlist ! Ok, that's fair. In my case, I wouldn't mind if only primitives and strings were checked for equality, but I understand if that might not be what the majority is looking for

bterrio avatar Feb 11 '22 02:02 bterrio

Related to this, I think it would be good to have a way to set the "original" value of a field. For example, saving a user's settings would set the original value of all the setting inputs to their current values, so only changes after the save would be considered as dirtying the field again.

jchanes04 avatar Mar 04 '22 17:03 jchanes04