dvdzkwsk / react-reformed

Make React forms simple again, see it here:
https://react-reformed.zuko.me/
MIT License
541 stars 32 forks source link

Question regarding Complex validation based on state of the model #18

Open farshid1 opened 6 years ago

farshid1 commented 6 years ago

Hi there,

The library is amazing and has taught me great deal of information. I am very new to react and I have come across a challenging validation problem. My validation is dependent on the state of the model. For example if a specific select option is selected a text field will appear and that's when the text field becomes required.

I'm still trying to get my head around HOCs so it's not very clear if they are indeed useful in my case (I have a strong feeling they are). Particularly I wanna be able to dynamically place different input elements on the form depending on the current state of the model (show/hide elements). This requires me to be able to remove and add properties to my model (which the reformed HOC does).

What happens in cases where validation must be applied on submit as oppose to synchronous validation. How can HOC solve such problems? I've been looking into the source code for a few hours and I mostly understand what's happening and the solution is great for simple forms. When complexities like dynamic field rendering and validation, I'm not sure how you can abstract these logics with the use of HOC. Any insight would be greatly appreciated.