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 32 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

@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 ffd8138.

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

☁️ Nx Cloud last updated this comment at 2025-02-17 22:33:17 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/lit-form

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

@tanstack/solid-form

npm i https://pkg.pr.new/@tanstack/solid-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: ffd8138

@harry-whorlow harry-whorlow marked this pull request as ready for review January 29, 2025 15:21
@harry-whorlow harry-whorlow force-pushed the on-submit-meta branch 2 times, most recently from 194411d to 50404a6 Compare February 4, 2025 10:23
@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.

@harry-whorlow harry-whorlow force-pushed the on-submit-meta branch 2 times, most recently from 1c981db to d43120a Compare February 4, 2025 15:06
Copy link

codecov bot commented Feb 17, 2025

Codecov Report

Attention: Patch coverage is 96.29630% with 1 line in your changes missing coverage. Please review.

Project coverage is 87.88%. Comparing base (990a916) to head (ffd8138).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
packages/react-form/src/useTransform.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1131      +/-   ##
==========================================
+ Coverage   87.86%   87.88%   +0.02%     
==========================================
  Files          30       30              
  Lines        1318     1321       +3     
  Branches      354      353       -1     
==========================================
+ Hits         1158     1161       +3     
  Misses        144      144              
  Partials       16       16              

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

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