vee-validate icon indicating copy to clipboard operation
vee-validate copied to clipboard

useForm() validateField() says field does not exist Vue 3

Open andrewkingg opened this issue 3 years ago • 1 comments

What happened?

When I use useForm() I'm able to call validate() fine and it returns the following:

Screen Shot 2022-02-16 at 9 14 46 PM

It shows I have a name and description field, but then when I call validateField('name') it says the field doesn't exist

Screen Shot 2022-02-16 at 9 14 53 PM

Reproduction steps

  1. call useForm() with initialValues
  2. call validateField() on one of the fields

...

Version

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

What browsers are you seeing the problem on?

  • [ ] Firefox
  • [X] Chrome
  • [ ] Safari
  • [ ] Microsoft Edge

Relevant log output

No response

Demo link

n/a

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

andrewkingg avatar Feb 17 '22 02:02 andrewkingg

This might be intended if you didn't call useField for that field name. Mainly because validateField tries to search for the field instance in the form:

https://github.com/logaretm/vee-validate/blob/main/packages/vee-validate/src/useForm.ts#L481-L486

The validate method isn't the same as it validates the form values regardless of what fields were actually registered.

I will tag this as an enhancement, for now, it would be ideal to eliminate this confusion.

logaretm avatar Feb 21 '22 21:02 logaretm

Closing since it is unlikely that you can validate a specific path that may represent a field or not.

logaretm avatar Mar 01 '23 23:03 logaretm