Closed cblberlin closed 10 months ago
@cblberlin can you deploy this code somewhere?
@cblberlin can you deploy this code somewhere? tried to find a way to do that, like in codesandbox?
@cblberlin can you deploy this code somewhere? tried to find a way to do that, like in codesandbox?
Yes... will be able to understand the code better. And can run it also
@cblberlin can you deploy this code somewhere? tried to find a way to do that, like in codesandbox?
Yes... will be able to understand the code better. And can run it also
I've successfully deployed a multiple-entries form on CodeSandbox: multiple-entries-form, although it's quite slow. Additionally, you can review the project on this GitHub repository: here. While there are some Chinese characters in it, they are primarily for basic functions like add, remove, and submit.
I got what you are trying to do...
I think you should create a new form every time you hit the add button and validate that form fields only instead of validating all the fields in one single form.
One you validate the 1st form, add the values to an array and then validate the second form and so on... and finally use the final array on Submit
button. That way all the objects in your array will already be validated and the code will be much simpler.
You are using index and adding that to name field, which means the value property will always change and zod validation will most likely fail
I got what you are trying to do...
I think you should create a new form every time you hit the add button and validate that form fields only instead of validating all the fields in one single form.
One you validate the 1st form, add the values to an array and then validate the second form and so on... and finally use the final array on
Submit
button. That way all the objects in your array will already be validated and the code will be much simpler.You are using index and adding that to name field, which means the value property will always change and zod validation will most likely fail
that's a very good approach, i'll try to figure out how to fix this and i will submit my result
I got what you are trying to do...
I think you should create a new form every time you hit the add button and validate that form fields only instead of validating all the fields in one single form.
One you validate the 1st form, add the values to an array and then validate the second form and so on... and finally use the final array on
Submit
button. That way all the objects in your array will already be validated and the code will be much simpler.You are using index and adding that to name field, which means the value property will always change and zod validation will most likely fail
Another potential method involves utilizing useFieldArray
from react-hook-form
to handle adding and removing actions, which helps in maintaining the array's structure when managing forms. I will experiment with both approaches.
Yup... works fine. But it never was a shadcn/ui issue. You can close it.
I've successfully implemented the multi-entries form. Although it wasn't an issue specific to shadcn-ui, this solution might be useful for others looking to create a similar form. By modifying the shadcn-ui example provided on Form
component, I hope it can assist anyone facing the same issue. Thanks to everyone who helped me resolve the error.
hi everyone, i'm writing a from which is a multi-entries form, but after submit, it return an object not an array
the console.log show me the submit value as an object:
but it expect the output as an array otherwise it won't pass the validation:
here is my schema:
and here is the form:
i don't know at which step the submit result turn into an object instead of an array