DEV Community

Dynamic form fields using React with hooks

Vimalraj Selvam on March 13, 2019

I'm trying to create a form where I'm letting user to add as many number of input fields and also giving an ability to remove any particular adde...
Collapse
 
one_punch_007 profile image
one_piece

It's amazing solution, but when using drop-down instead of input, then having issue. If I have two drop-down, on the base of one selection other drop-down appear and I change value. But if I change again the value of first drop-down, the second drop-down value is not reset in UI. I have around 4 type of second field which appear on the base of first drop-down selection.

Collapse
 
pankhudisharma4 profile image
Sharma Pankhudi 👩🏻‍💻

I am having same issue. did you get solution for that?

Collapse
 
email2vimalraj profile image
Vimalraj Selvam

Solved this issue by making the input as controlled component after a reddit user helped.

Refer here.

Collapse
 
rayremnant profile image
RayRemnant

Thank you for sharing this, I've used your sample to built the same form as a WordPress Gutenberg block.

Really helpful and clear, sending some good vibes.

Collapse
 
email2vimalraj profile image
Vimalraj Selvam

Glad it helped!