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 #1167

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

Conversation

harry-whorlow
Copy link
Contributor

new branch after from #1131

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

Copy link

nx-cloud bot commented Feb 21, 2025

View your CI Pipeline Execution ↗ for commit 650144d.

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 1m 39s View ↗
nx run-many --target=build --exclude=examples/** ✅ Succeeded 24s View ↗

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

Copy link

pkg-pr-new bot commented Feb 21, 2025

Open in Stackblitz

More templates

@tanstack/angular-form

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

@tanstack/form-core

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

@tanstack/react-form

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

@tanstack/lit-form

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

@tanstack/solid-form

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

@tanstack/vue-form

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

commit: 650144d

Copy link

codecov bot commented Feb 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.33%. Comparing base (b0dc32c) to head (650144d).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1167   +/-   ##
=======================================
  Coverage   88.32%   88.33%           
=======================================
  Files          27       27           
  Lines        1199     1200    +1     
  Branches      315      316    +1     
=======================================
+ Hits         1059     1060    +1     
  Misses        125      125           
  Partials       15       15           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@harry-whorlow harry-whorlow marked this pull request as ready for review February 21, 2025 16:53
@harry-whorlow harry-whorlow mentioned this pull request Feb 21, 2025
2 tasks
Copy link
Member

@crutchcorn crutchcorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!!

Just checking, do we want to make these changes? WDYT?

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