logaretm / vee-validate

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

Custom errors get gone after submitting #3903

Closed mohammadali0120 closed 2 years ago

mohammadali0120 commented 2 years ago

What happened?

    "nuxt": "3.0.0-rc.8"
    "@vee-validate/rules": "^4.6.5",
    "vee-validate": "^4.6.5",
    "yup": "^0.32.11"

I think there is one problem with setting error manually when I set a manual error, e.g when I click on submit button, without any attention to my condition manual error gets disappeared I don't get this what would be the reason for an error to gets disappear without my condition getting true?

In the example link, you can see both composition-api and components approaches that both of them won't work as expected,

Am I made a mistake somewhere or this is a bug?

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

https://stackblitz.com/edit/nuxt-starter-udh7b4

Code of Conduct

logaretm commented 2 years ago

That is expected. When you click submit vee-validate clears the errors and replaces them with the ones it knows about by running the validation rule.

If you want to have custom errors then you need to set them after submission. I don't see you trying to set them anywhere other than after input which is unrelated to submit events.

Luckily it is easier to do so than with input events, you can call actions.setErrors in the submit handler. Like here in the docs.

The same mechanism exists for components API as well.

https://stackblitz.com/edit/nuxt-starter-fjxqfr?file=pages%2Findex.vue,components%2FMyInputComponent.vue