Validating Simple Array of Objects (v4) #4839
Unanswered
alecStewart1
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I apologize ahead of time if this question has been asked repeatedly, but I'm finding it difficult to get a clear cut answer for something I would think is a pretty common scenario.
I'll try to keep this as simple as possible as to maybe be helpful for anyone who comes across this.
In a project, you want to have a form to add multiple people by their first and last name. Using
vee-validate
andzod
, we know the following:So our schema will look like so to start:
Simple as. However we want to be able to add or remove potential people from a list, not just be able to add one at a time. So we now have the following:
We now attach this to the
useForm
composable:Now, assuming we go along with that's in the documentation, we need to use
useFieldArray
:Now we need to create the actual template for the application. Presumably we have to do something like this:
And then of course we could add in the "Add" and "Remove" buttons.
My question is: is this a correct pattern?
I highly doubt this is an unusual usecase, but I wanted to confirm this is how you would handle something like this.
Beta Was this translation helpful? Give feedback.
All reactions