DEV Community

Brendon Chirume
Brendon Chirume

Posted on

how can I deal with controlled and uncontrolled input in reactjs

I have a form field shown in the picture below
image
The product field is a search field with suggestions when the user clicks the suggested option other form fields are filled automatically, the user can also override what has been filled automatically let's say price. On successful completion of the form, the details are added to a table. Now I'm facing a challenge when the user cancels the process after an autofill it doesn't override the previous values and this happens when I'm using the defaultValue attribute. So I have tried using a value attribute and an onChange handler I can only type in the fields before an autofill meaning the user can not change fields like price after an autofill so how best can I tackle my problem.

Top comments (0)