nuxt / nuxt/ui

Nested form onSubmit handler type mismatch

Open
#5,115 8 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
6.9k
Forks
1.1k
Avg merge
1d 7h
Merged PRs (30d)
57

Description

Package

v3.x

Description

I am trying to migrate from nuxt ui v2 to v3 and I experienced a problem with complex forms.
I started to re-implement everything with the new nested forms pattern but I finally have a problem with the defined type of the submit handler.

The defined type of the handler is the following:
onSubmit?: ((event: FormSubmitEvent<FormData<S, T>>) => void | Promise<void>) | (() => void | Promise<void>);

Where S is the schema passed to the form. With nested forms the data passed to the handler must be the combination of the main form with the addition of the data from the nested one.

Keeping the example in the documentation as reference the onSubmit handler must have as input parameter event: FormSubmitEvent<Schema> but Schema is a subpart of the total data received from the form.

The console.log print all data (also from nested forms) but is not type safe and to use that data to perform a mutation is necessary a cast (not so good in my opinion).

Do you have some suggestion?

Thanks,

Federico

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the nested forms section of the Nuxt UI documentation and trace the onSubmit and FormSubmitEvent type definitions described in the issue. Reproduce the documented nesting example, then verify that the handler receives the combined parent and nested data without a cast and that the result type-checks.

Written by the indexing model from the issue text.

Assessment

Tech stack
nuxt, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.