Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to accept empty array on form validation? #260

Open
mattp0123 opened this issue Oct 23, 2024 · 3 comments
Open

How to accept empty array on form validation? #260

mattp0123 opened this issue Oct 23, 2024 · 3 comments
Assignees
Labels
question Further information is requested

Comments

@mattp0123
Copy link

I have a form like this:

const MyForm = v.object({
  items: v.array(
    v.object({ foo: v.string() })
  ),
})

type MyForm = v.InferInput<typeof MyForm>

const formStore = useFormStore<MyForm>({
  fieldArray: ['items'],
  loader: { value: { items: [] } },
  validate: valiForm$(MyForm),
})

When I submit the form with the empty items field, the validation won't pass.

@fabian-hiller
Copy link
Owner

Can you provide a minimal reproduction via StackBlitz? Here is a template: https://stackblitz.com/edit/modular-forms-qwik?file=src/routes/todos/index.tsx

@fabian-hiller fabian-hiller self-assigned this Oct 23, 2024
@fabian-hiller fabian-hiller added the question Further information is requested label Oct 23, 2024
@mattp0123
Copy link
Author

mattp0123 commented Oct 24, 2024

@fabian-hiller here's the reproduction. by clicking the submit button, this error shows up:

image

@fabian-hiller
Copy link
Owner

Thank you! Does this workaround work for you?

const FormSchema = v.object({
  heading: v.string(),
  todos: v.optional(
    v.array(
      v.object({
        label: v.string(),
        deadline: v.string(),
      })
    )
  ),
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants