Skip to content

Commit

Permalink
clear errors when validation passes
Browse files Browse the repository at this point in the history
  • Loading branch information
Smef committed Jun 7, 2024
1 parent 14966a3 commit 389b192
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/runtime/composables/usePrecognitionForm.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FetchContext, FetchResponse } from 'ofetch'
import type { FetchContext, FetchResponse } from 'ofetch'
import useForm from './useForm'

export default function usePrecognitionForm<Data extends Record<string, unknown>>(method: RequestMethod, url: string | (() => string), data: Data) {
Expand Down Expand Up @@ -69,6 +69,14 @@ async function validate(fieldName: string) {

await defaultOptions.onStart()
},
onResponse: async (context: FetchContext & { response: FetchResponse<R> }): Promise<void> | void => {
if (!context.response.ok) {
return
}

// clear the errors for the validated fields
await this.clearErrors(validateOnly)
},
onResponseError: async ({ response }) => {
console.log('precognition onResponseError')
const errors = response._data.data?.errors
Expand Down

0 comments on commit 389b192

Please sign in to comment.