Skip to content

Commit fef4783

Browse files
committed
fix(useForm): correct error handling in onError callback
Update the onError callback to assign errors to the local variable instead of form.errors and ensure the correct parameter is passed to user-defined onError handlers. Also, call form.defaults() after successful submission if defaults were not set in onSuccess.
1 parent 0d719a1 commit fef4783

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

packages/svelte5/src/useForm.svelte.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,18 +223,18 @@ export default function useForm<TForm extends FormDataType<TForm>>(
223223
const result = options.onSuccess ? await options.onSuccess(page) : null
224224

225225
if (!defaultsCalledInOnSuccess) {
226-
defaults = cloneDeep(getData())
226+
form.defaults()
227227
}
228228

229229
return result
230230
},
231-
onError: async (errors) => {
231+
onError: async (errorResponse) => {
232232
processing = false
233233
progress = null
234-
form.errors = errors as FormDataErrors<TForm>
234+
errors = errorResponse as FormDataErrors<TForm>
235235

236236
if (options.onError) {
237-
return await options.onError(errors)
237+
return await options.onError(errorResponse)
238238
}
239239
},
240240
onCancel: () => {

0 commit comments

Comments
 (0)