Change defaults values order in onSuccess callback of useForm #2437
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.
I found a weird issue in Svelte
useForm.The
$form.reset()inonSuccesscallback won't work, but inonErrorcallback, it works just fine.const form = useForm({ current_password: "", password: "", password_confirmation: "", }); // type the new password and submit // I think the $form.reset() will reset all the input to empty string // but it doesn't $form.put(route('password.update'), { preserveScroll: true, // reset in onSuccess won't work onSuccess: () => $form.reset(), onError: (errors: any) => { // reset in onError callback is work $form.reset() }, });After diving into the codebase, I found the task order in Svelte
onSuccessis a little different with Vue version.In the Vue
onSuccess, the user's callback will execute beforedefaults = cloneDeep(this.data()), so the user can useform.reset()to reset the form values, then set the form values as the default values.But in the Svelte
onSuccess, the user's callback will execute afterthis.defaults(cloneDeep(this.data())).I think this is the issue, because
this.defaults()has already changed the value to user type before,$form.reset()does not set form values to the empty string. I think this may not be what the user expects.So I just change the task order below.