diff --git a/packages/react-inertia/src/index.ts b/packages/react-inertia/src/index.ts index a454071..d83258e 100644 --- a/packages/react-inertia/src/index.ts +++ b/packages/react-inertia/src/index.ts @@ -160,26 +160,18 @@ export const useForm = >(method: RequestMet return form }, submit(submitMethod: RequestMethod | Config = {}, submitUrl?: string, submitOptions?: any): void { - const isPatchedCall = typeof submitMethod !== 'string' - - submitOptions = isPatchedCall - ? submitMethod - : submitOptions - - submitUrl = isPatchedCall - ? resolveUrl(url) - : submitUrl! - - submitMethod = isPatchedCall - ? resolveMethod(method) - : submitMethod as RequestMethod + if (typeof submitMethod !== 'string') { + submitOptions = submitMethod + submitUrl = resolveUrl(url) + submitMethod = resolveMethod(method) + } - inertiaSubmit(submitMethod, submitUrl, { + inertiaSubmit(submitMethod, submitUrl!, { ...submitOptions, onError: (errors: SimpleValidationErrors): any => { precognitiveForm.validator().setErrors(errors) - if (submitOptions.onError) { + if (submitOptions?.onError) { return submitOptions.onError(errors) } }, diff --git a/packages/vue-inertia/src/index.ts b/packages/vue-inertia/src/index.ts index f6d201f..5403bee 100644 --- a/packages/vue-inertia/src/index.ts +++ b/packages/vue-inertia/src/index.ts @@ -178,8 +178,8 @@ export const useForm = >(method: RequestMet onError: (errors: SimpleValidationErrors): void => { precognitiveForm.validator().setErrors(errors) - if (submitOptions!.onError) { - return submitOptions!.onError(errors) + if (submitOptions?.onError) { + return submitOptions.onError(errors) } }, })