christianalfoni / formsy-react

A form input builder and validator for React JS
MIT License
2.6k stars 436 forks source link

Any way to not require my form field components to be direct children of the Formsy? #121

Closed tedlin182 closed 9 years ago

tedlin182 commented 9 years ago

I have multiple sections for my overall form which I broke out into components and within those I have the form field components.

Formsy requires the form field components to be direct children, so I get errors regarding that which makes it difficult to organize my components and break them into reasonable, reusable chunks. The way Formsy is setup forces me to have to create a massive form component which isn't great.

Any reason for this requirement though and if there's a way around this?

ivome commented 9 years ago

Seems to be along the lines of #120 If we would have something like form nesting, we could organize the components way better.

shatran commented 9 years ago

I have the same issue. My form is also complex with multiple layers, and i couldn't get any separation for the different form sections, and of course i couldn't build reusable components that are parents of the inputs components. Wish this issue could be fixed in the near future. BTW Thanks for this awesome library!

christianalfoni commented 9 years ago

Hi guys!

I was hoping React 0.14 would be right around the corner with its parent-child context. That should solve the issue without any changes.

It should be possible to fix it with a mixin too. let me try out an implementation so that it will be easy to switch when React 0.14 gets here

nathanwelch commented 9 years ago

Hey @christianalfoni did you ever get a chance to try implementing the solution you were referring to that doesn't require React 0.14? I think it was what you were referring to here with the extended prop that would cause Formsy.Form to return a <div> instead of a <form> if it was nested: https://github.com/christianalfoni/formsy-react/issues/120#issuecomment-104406816.

I implemented it in a fork to play around with nesting forms: https://github.com/christianalfoni/formsy-react/compare/master...smashgg:nested-forms. It seems to work so far but I did it pretty quickly and I'm sure I missed something.

Just curious: are you planning to release a version that would support nested forms before React 0.14 is out?

iandeherdt commented 9 years ago

I tried @nathanwelch his solution and it seems to work. Can this be merged into the current branch please?

christianalfoni commented 9 years ago

Hi guys,

I will check out the suggestion as soon as I can and if it does not break anything I will bring it into next release :-) Thanks for taking the time @nathanwelch!

christianalfoni commented 9 years ago

React 0.14 is in BETA now, and right around the corner. Implemented with context now, and other fixes. This will be the next release as soon as React 0.14 is released. Sorry for the wait, but this is the best solution (I would say).

stephenrs commented 9 years ago

In case it helps someone while we're waiting for React 0.14, I can confirm that the solution proposed by @nathanwelch is working (so far) quite well for splitting up big forms into separate components. I'm using it with react-bootstrap (TabbedArea/TabbedPane) to display a complex form across several tabs.

Thanks @nathanwelch, @christianalfoni, and thanks for the discussion guys!