Search code examples
vuejs3vee-validatepinia

Using Object in Pinia Store, how to validate it with vee-validate


In my pinia store I have an object like so

const quiz = ref({ title: “”, description: “”})

I am referencing this object in a form with couple of inputs bound to v-model like

<input type=“text” v-model=“quiz.title” />

<input type=“text” v-model=“quiz.description ” />

I would like to validate the quiz object with vee-validate. But I can’t seem to find a correct example to do so. I have looked at this https://vee-validate.logaretm.com/v4/examples/using-stores but it’s again not validation for object.

How do i validate with vee-validate while my v-model remains as-is (i.e quiz.xxx) . Sample code is available on stackblitz


Solution

  • Found the answer after a bit of digging after @cwillinx comment. I had to reference the error object in the form like so

    store.errors['quiz.title']

    instead of

    store.errors.title