Skip to content

Conversation

@jvllmr
Copy link
Contributor

@jvllmr jvllmr commented Aug 24, 2025

This allows type-safely passing a form to a func which accepts a form with only selected fields of the original form.

Here an example:

import { UseFormReturnType, useForm } from '@mantine/form';



function PasswordSection<TForm extends UseFormReturnType<{password: string}>(
  {form}: {form: TForm}
) {
  // add buttons such as password generator button
  // ...
}

interface SignupFormValues {
  username: string;
  password: string;
}

export function SignupForm() {
  const form = useForm<SignupFormValues>({ initialValues: { username: '', password: '' } })
   
  return <form>
  {
  // ...
  }
  <PasswordSection form={form} />
  {
  // ...
  }
 </form>;
}

Related discussions:

This is just a proposal. Feel free to close the PR if you'd like.
I needed to create a new UseFormReturnType, but kept the old one around so that no breaking changes are made.
Edit: It is possible without an extra type

This allows passing a form to a func which accepts a form with only selected fields of the original form

Signed-off-by: Jan Vollmer <[email protected]>
@jvllmr jvllmr marked this pull request as draft August 24, 2025 10:28
@jvllmr jvllmr marked this pull request as ready for review August 24, 2025 11:25
@jvllmr
Copy link
Contributor Author

jvllmr commented Aug 24, 2025

I also looked into improved inference and value passing for the TransformValues / TransformedValues type, but I think for that TransformValues must be removed in favor of using only TransformedValues. But that would be a breaking change. I could start to create a draft PR for v9 though if there is interest.

@jvllmr
Copy link
Contributor Author

jvllmr commented Sep 8, 2025

@rtivital could you already take a look at this PR? Would be happy about any feedback.

@rtivital
Copy link
Member

rtivital commented Sep 8, 2025

Yes, I've reviewed it, but I do not fully understand the new TS syntax (out part). I need more time for a deep dive.

@jvllmr
Copy link
Contributor Author

jvllmr commented Sep 8, 2025

Okay, take your time 👍🏻 Thanks for letting me know.

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