Skip to content

[Feature request] Form Composition: Ability to compose set of common fields to multiple different form #1475

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

Open
valerii15298 opened this issue May 2, 2025 · 3 comments

Comments

@valerii15298
Copy link

Would be good to have ability to compose set of fields to different forms that have same common field using typescript.

react-hook-form already has such functionality via Lenses: https://github.com/react-hook-form/lenses

Original feature request which ended up by creating lenses for react-hook-form: https://github.com/orgs/react-hook-form/discussions/7354

Overview
Imagine this structure of forms:

interface Address {
  street: string
  houseNumber: number
  city: string
  country: string
}

interface Person {
  name: string
  address: Address
}

interface Order {
  item: string
  shippingAddress: Address
}

I wanna create component to display Address part of any form.
So that in other forms(like Order and Person and many more which will have address field structure) I can declaratively reuse Address fields by just providing basePath to them and having correct typescript validation and typings.

@LeCarbonator
Copy link
Contributor

Would #1469 be the kind of thing you're looking for? It's not confirmed to be added, but if you have feedback on the implementaion, let me know.

@valerii15298
Copy link
Author

@LeCarbonator yep, seems like what i asked for. Thank you! But still would be good to have an api as simple and flexible at the same time as possible. Like react hook form lenses has. They have lens.reflect(...) for example which allows to map fields with different names to the fields which nested lense part expects. And for now RHF lenses api seems just simpler and more flexible as i see.

But overall yes, this is the direction i was asking for

@LeCarbonator
Copy link
Contributor

@LeCarbonator yep, seems like what i asked for. Thank you! But still would be good to have an api as simple and flexible at the same time as possible. Like react hook form lenses has. They have lens.reflect(...) for example which allows to map fields with different names to the fields which nested lense part expects. And for now RHF lenses api seems just simpler and more flexible as i see.

But overall yes, this is the direction i was asking for

I see! Perhaps there's a way to implement that. As it is right now, the reason the mapping wasn't supported is because validation can simply be inherited from the field instead of requiring reflection on all properties.

I'll look into it!

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

No branches or pull requests

2 participants