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

feat(core) onSubmit meta #1131

Open
wants to merge 26 commits into
base: main
Choose a base branch
from

Conversation

harry-whorlow
Copy link
Contributor

@harry-whorlow harry-whorlow commented Jan 28, 2025

From issue #989, this PR introduces onSubmitMeta to the formApi.

Example API shamelessly ripped from #989 and @crutchcorn

const form = useForm({
    defaultValues: {
      firstName: '',
      lastName: '',
    },
    // Is 'never' by default unless you provide a type
    // {} is the default value passed to `onSubmit`'s `meta` property
    onSubmitMeta: {} as { someValue: string },
    onSubmit: async ({ value, meta }) => {
      // Do something with form data
      console.log(value)
      // Do something with the values passed via handleSubmit
      console.log(meta)
    },
  })

  return (
    <div>
      <h1>Simple Form Example</h1>
      <form
        onSubmit={(e) => {
          e.preventDefault()
          e.stopPropagation()
          form.handleSubmit({
            someValue: 'value',
          })
        }}
      >

Screenshot 2025-01-28 at 10 17 44
  • working overloads
  • Tests
  • LGTM 🚀

@harry-whorlow harry-whorlow marked this pull request as draft January 28, 2025 09:33
Copy link

nx-cloud bot commented Jan 28, 2025

View your CI Pipeline Execution ↗ for commit 27cffc8.

Command Status Duration Result
nx run-many --target=build --exclude=examples/** ✅ Succeeded 30s View ↗

☁️ Nx Cloud last updated this comment at 2025-02-06 07:39:54 UTC

Copy link

pkg-pr-new bot commented Jan 29, 2025

Open in Stackblitz

More templates

@tanstack/angular-form

npm i https://pkg.pr.new/@tanstack/angular-form@1131

@tanstack/form-core

npm i https://pkg.pr.new/@tanstack/form-core@1131

@tanstack/react-form

npm i https://pkg.pr.new/@tanstack/react-form@1131

@tanstack/solid-form

npm i https://pkg.pr.new/@tanstack/solid-form@1131

@tanstack/lit-form

npm i https://pkg.pr.new/@tanstack/lit-form@1131

@tanstack/valibot-form-adapter

npm i https://pkg.pr.new/@tanstack/valibot-form-adapter@1131

@tanstack/vue-form

npm i https://pkg.pr.new/@tanstack/vue-form@1131

@tanstack/yup-form-adapter

npm i https://pkg.pr.new/@tanstack/yup-form-adapter@1131

@tanstack/zod-form-adapter

npm i https://pkg.pr.new/@tanstack/zod-form-adapter@1131

commit: 27cffc8

@harry-whorlow harry-whorlow marked this pull request as ready for review January 29, 2025 15:21
@harry-whorlow
Copy link
Contributor Author

I'm going to give it a go as the generic not extending object, I'm a little unsure why I started with it like this. But, I think restricting the user to what type they can define is a miss-step.

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

Successfully merging this pull request may close these issues.

2 participants