logaretm / vee-validate

✅ Painless Vue forms
https://vee-validate.logaretm.com/v4
MIT License
10.85k stars 1.28k forks source link

setErrors/setFieldError does not work after re-render #4938

Closed RossLote closed 1 week ago

RossLote commented 2 weeks ago

What happened?

<script lang="ts">

const stepIndex = ref(0)

function onSubmit(setErrors, goToStep) {
    // get errors from server
    goToStep(1)
    setErrors({...})
    // No errors are displayed on the step we navigate to
}

</script>

<template>
    <Form
        as="div"
        :key="stepIndex"
        v-slot="{ setErrors }"
        keep-values
        :initial-values="initialValues"
        :validation-schema="toTypedSchema(schemaObjects[stepIndex - 1])"
    >
        <Stepper
            v-slot="{ goToStep }"
            v-model="stepIndex"
        >
            <form @submit="onSubmit( setErrors, goToStep )">
                ...
            </form>
        </Stepper>
    </Form>
</template>

I've attempted setting timeouts at various points to see if there is a re-rendering issue but that doesn't work. If I set the errors 5 seconds after the step change then nothing happens.

If I set errors on the step I'm currently on then the errors show correctly.

The stepper I'm using is this: https://www.radix-vue.com/components/stepper.html#api-reference

Reproduction steps

1. 2. 3. ...

Version

Vue.js 3.x and vee-validate 4.x

What browsers are you seeing the problem on?

Relevant log output

No response

Demo link

none

Code of Conduct

logaretm commented 2 weeks ago

If I set errors on the step I'm currently on then the errors show correctly.

I believe that is the expected behavior here, are you setting errors for fields that don't exist yet? A minimal example would be great.