mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-14 12:14:41 +01:00
fix(Form)!: resolve async validation in yup & issue directly mutate state (#2702)
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
@@ -104,6 +104,7 @@ function resolveErrorIds(errs: FormError[]): FormErrorWithId[] {
|
||||
}))
|
||||
}
|
||||
|
||||
const parsedValue = ref<T | null>(null)
|
||||
async function getErrors(): Promise<FormErrorWithId[]> {
|
||||
let errs = props.validate ? (await props.validate(props.state)) ?? [] : []
|
||||
|
||||
@@ -112,7 +113,7 @@ async function getErrors(): Promise<FormErrorWithId[]> {
|
||||
if (errors) {
|
||||
errs = errs.concat(errors)
|
||||
} else {
|
||||
Object.assign(props.state, result)
|
||||
parsedValue.value = result
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,7 +170,7 @@ async function onSubmitWrapper(payload: Event) {
|
||||
|
||||
try {
|
||||
await _validate({ nested: true })
|
||||
event.data = props.state
|
||||
event.data = props.schema ? parsedValue.value : props.state
|
||||
await props.onSubmit?.(event)
|
||||
} catch (error) {
|
||||
if (!(error instanceof FormValidationException)) {
|
||||
|
||||
Reference in New Issue
Block a user