Skip to content

Commit

Permalink
fix(Form)!: resolve async validation in yup & issue directly mutate s…
Browse files Browse the repository at this point in the history
…tate (#2701)
  • Loading branch information
rdjanuar authored Nov 23, 2024
1 parent dbd2aed commit f3632dd
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/runtime/components/forms/Form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export default defineComponent({
const formId = useId()
const bus = useEventBus<FormEvent>(`form-${formId}`)
const parsedValue = ref(null)
onMounted(() => {
bus.on(async (event) => {
if (event.type !== 'submit' && props.validateOn?.includes(event.type)) {
Expand Down Expand Up @@ -87,7 +89,7 @@ export default defineComponent({
if (errors) {
errs = errs.concat(errors)
} else {
Object.assign(props.state, result)
parsedValue.value = result
}
}
Expand Down Expand Up @@ -130,7 +132,7 @@ export default defineComponent({
if (props.validateOn?.includes('submit')) {
await validate()
}
event.data = props.state
event.data = props.schema ? parsedValue.value : props.state
emit('submit', event)
} catch (error) {
if (!(error instanceof FormException)) {
Expand Down Expand Up @@ -321,7 +323,7 @@ async function validateYupSchema(
schema: YupObjectSchema<any>
): Promise<ValidateReturnSchema<typeof state>> {
try {
const result = schema.validateSync(state, { abortEarly: false })
const result = await schema.validate(state, { abortEarly: false })
return {
errors: null,
result
Expand Down

0 comments on commit f3632dd

Please sign in to comment.