react icon indicating copy to clipboard operation
react copied to clipboard

Controlled input makes browser not saving submitted value (for autocomplete)

Open bootleq opened this issue 5 years ago • 11 comments

Bug (behaves different per browser, but generally inconsistent to uncontrolled inputs)

Current behavior Reproduce with https://jsfiddle.net/bootleq/hos4r6qd/

  1. Type a in name field, and b in uncontrolled field.
  2. Submit.
  3. Re-run the fiddle.
  4. Focus input fields to see if browser "saves" previous input.

Expected behavior Browser provides a suggestion for name and b for uncontrolled field. Controlled and uncontrolled elements should behave the same.

Actual result Uncontrolled input has b suggestion, but controlled input (name) has no suggestion. Tested on Windows 7, Google Chrome 74.0.3729.169. And on Firefox 68.0b4, we can click the workaround button before submit, by reset the value DOM attribute it behaves as expected.

bootleq avatar May 25 '19 12:05 bootleq

Uncontrolled value saved on the window, whereas the controlled input value saved in their state. Once the state has gone their value gone as well.

anupmishra203 avatar Jun 04 '19 10:06 anupmishra203

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution.

stale[bot] avatar Jan 10 '20 07:01 stale[bot]

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!

stale[bot] avatar Jan 17 '20 07:01 stale[bot]

Oh wow. Good find. I guess this is also due to attribute syncing. We're going to fix this eventually but it would be a breaking change so for now let's keep it open.

gaearon avatar Apr 01 '20 22:04 gaearon

@gaearon: Are there any plans to fix this? It almost 2 years since the report and at least in my eyes this is a huge UX bug.

This bug affects other frameworks (antd, material UI):

  • mui-org/material-ui#16943
  • ant-design/ant-design#21232

I'm also not getting it, why this one should be a breaking change.

If autoComplete is "on" react could to this setAttribute('value', ''); under the hood and it would be fine. Or are there any side effects if you are doing this?

Hadsch avatar Jan 30 '21 10:01 Hadsch

Same problem here

hejtmii avatar May 07 '21 14:05 hejtmii

autoComplete is Not working for controlled Input.

https://jsfiddle.net/bootleq/hos4r6qd/

snehabn92 avatar Oct 05 '21 13:10 snehabn92

This also affects Formik performance, which is very bad https://github.com/formium/formik/issues/3165

handhikadj avatar Oct 08 '21 09:10 handhikadj

I am not even using controlled input. Still I am facing this issue when using Firefox. I am just using input type text and the fetching the value using id on the time of submit form. Still it won't show the auto-fill suggestion box. Anyone has any idea? I have already kept "Remember search and form history" in Firefox settings checked.

TejSanura avatar Jan 11 '22 12:01 TejSanura

Just to mention that there is a "workaround" (=wild hack) we used successfully for more than a year now: https://github.com/facebook/react/issues/18986#issuecomment-636354428

ahoisl avatar Jan 11 '22 12:01 ahoisl

There actually has been some activity on the Firefox side to solve this: https://bugzilla.mozilla.org/show_bug.cgi?id=1642570

It's already working in Firefox Nightly for me and seems to be scheduled for release in version 105, 2022-09-20

lindskogen avatar Aug 15 '22 13:08 lindskogen

Tested it right now in Firefox 106.0.3 and it seems to work!

lindskogen avatar Nov 02 '22 12:11 lindskogen