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

Make isDirty reactive to defaults #2236

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mochetts
Copy link

@mochetts mochetts commented Feb 14, 2025

Problem

The isDirty prop is not reactive as it is for the vue package.
This causes several issues such as the form staying as dirty even after a successful submit.

Reason

The defaults are not being set as the data after a successful submission.

Solution

Set the defaults as the submitted data upon a sucessful submit.
See vue3 implementation as it's doing exactly that.

@@ -69,6 +70,10 @@ export default function useForm<TForm extends FormDataType>(
}
}, [])

useEffect(() => {
setIsDirty(!isEqual(data, defaults))

This comment was marked as outdated.

@@ -111,6 +116,7 @@ export default function useForm<TForm extends FormDataType>(
setHasErrors(false)
setWasSuccessful(true)
setRecentlySuccessful(true)
setDefaults(data)
Copy link
Author

@mochetts mochetts Feb 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should reset the isDirty prop back to false.

@mochetts mochetts changed the title Make isDirty reactive Make isDirty reactive to defaults Feb 14, 2025
The isDirty prop is not reactive as it is for the vue package.

This causes several issues such as the form staying as dirty even after submitting a successful request.

Or even after setting the defaults to be the same as the form data:
inertiajs#2109
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

Successfully merging this pull request may close these issues.

1 participant