vee-validate: Add a way to get all errors to ValidationObserver
Is your feature request related to a problem? Please describe. I really like the changes in v3. It’s solved a lot of the issues with componentizing forms (no more inject!) and displaying errors, etc. However, I keep wanting to have some concise way to get all the errors on the page. Either for debugging or for displaying the first error on submit or scrolling the form back up to the error message, etc.
Describe the solution you’d like
Add getErrors or some other interface to ValidationObserver to get some sort of error list. validate and setErrors already exists so it would seem natural to add a getErrors.
Describe alternatives you’ve considered
The validate method could return more than true/false but that seems a bit kludgy. An error-model or something similar could be used to store errors based on events.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 16
- Comments: 15 (5 by maintainers)
@d3radicated, I try to check “this.$refs.observerRef.errors” right after validation() execution (in ‘then’ section), and it is empty. But if I set timeout to 100ms this.$refs.observerRef.errors has filled with correct error descriptions. If I try to get errors through ValidationProvider ref, all is Ok and I get errors immediately.
Look like propagation errors from
ValidationProvider-s toValidationObserveris async taskIf you would like to get errors after validation,
Current workaround until a better way is published:
This will ignore the
_vee_nkeys and will flat their values (validation messages) into a final array.Currently, you can get the errors from the slot scope of the observer. Or using
$refs.observerRef.ctx.errors.But I will think of a better way to get it soon.
Tagged in
3.4.0Thevalidatefunction now automatically updates the state of theobserverso timeouts are no longer neccessary aftervalidate.validateWithInfois also a new function available on observers, it gives you access to all errors in it’s fullfilled callback.Workaround from @sin314 works!
$refs.observerRef.ctx.errorsis helpful, thanks. It’s definitely not ideal since it returns all the inputs even if they have no errors. And the values are indexed on_vee_nwhich doesn’t really apply to anything on the page.