Replies: 1 comment 1 reply
-
Thanks for posting this, I don't get a lot of feedback on array fields support. In any case, I don't really have a guess into why it would pass the wrong values to the yup schema.
This was just fixed in 79d3779 You can find this change published in |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I apologize in advance for the lengthy explanation below.
I've been trying to implement array fields in my form. I've run into several issues / headaches. The biggest is how to properly handle initial values and form reset. I've created a sandbox where I have duplicated most of my application's form logic that handles resetting array fields.
(see notes on the sandbox near the bottom of this post)
https://codesandbox.io/s/vee-validate-array-field-validation-wike2
I confess to being a relatively new to Vue (this project is my first experience and I have only been using it for about 3 months). So there are probably (definitely?) some poor practices being used on my part.
Right now to get reset and add/remove working with
Clusterfield
(what I call my custom field type that consists of a block of array fields) I tap into the model exposed byuseField
. With that I am able to manhandle / coordinate the visual array and the data contained within. I have had to use template refs to directly call each instance of cluster when doing a reset. This also lead me to usecloneDeep
when doing resets to prevent the "source of truth"(original data loaded from an api) being changed.HALP! / My Application's bug
Just to make it crystal clear, the codesandbox example works exactly as I want my application to function. I mainly started this sandbox to try and recreate a bug I see in my project where array fields are not validating properly. However even after nearly mirroring all the various component / nested components / logic from my project into this sandbox I can't recreate the issue.
In my project once the array fields are available the validation only appears to fire once and does not seem to be passing the correct / newest field model values to the yup schema. After that first validation event fires for the array field, no matter what value is in the input field it never passes validation. If I click submit I can see the correct data has been populated in
useForm
values model. It does not matter if the field has initial data or not. I've also tried retooling everything to avoiduseField
inClusterField
and pass in initial "amount of clusters to display" as a prop. That had the same issue. So I am at a complete loss as to what is going on.As you can imagine this is the worst kind of issue to try and debug as I cannot recreate the issue in the codesandbox using identical code (the only difference that I can note is the use of Vue router / router-view in my project).
I have tried so many different permutations in my project and the codesandbox. No matter what I tried I cannot fix / find the issue in my application OR recreate the same issue in the codecodebox.
I'm looking for any ideas as why my issue above might be occurring (or ways I could better debug on my end) and if there are suggestions on a better way to handle array fields with initial values and form resets.
Notes on the sandbox
onMounted
method:AnyField
is modification (bastardization?) of the "Build a Form Generator"ClusterField
custom field to handle a field / data type that is made up of array fieldsFieldWrapper
is a simple wrapper to add a label, error message, help text, and bootstrap CSS.DynamicFields
will render an array fields based on their render properties.DynamicFields
as this makes getting at those things easier in the event of a nestedDynamicFields
.useField
and array fields was intended / supported. However, if you attempt to implementuseField
without have passed any kind of data to the initial values (viauseForm
) of that field's name there is a runtime error when you click "Add [Field Label Here]".data
keys intheData.js
to see.Cannot use 'in' operator to search for '0' in undefined
Beta Was this translation helpful? Give feedback.
All reactions