fixes for svelte's useForm helper #1610
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes two issues in useForm helper that I found.
data
is shallow copied todefaults
. Updating nested objects in form updatesdefaults
object as well. Since the current form data is compared todefaults
, no changes are detected.setStore
. Svelte's stores replaces store value with anything it receives fromupdate
's callback function. In this casesetStore
creates completely new object instance every time it's called by returningObject.assign({}, store, ...)
. Later when form submit fails,this.clearErrors().setError(errors)
is called on object instance that request was made from which is NOT the object currently stored in form store hence nothing is cleared.This should fix form error issue in #1521 #1276
Edit:
Added two more fixes:
- updating defaults to current data after successful request. It's debatable but IMO form defaults should be updated because previous form state is irrelevant after successful submit.I see that Vue adapters work very similarly to the changes I made.