`updateInputsWithValue` doesn't trigger `onChange`?
See original GitHub issueI have a form that saves its content every time 3 seconds after a user typing event, to localStorage
.
And if user refreshes page, the content inside localStorage
will be loaded and the form is updated with that content by updateInputsWithValue
.
Also there is a button that submit the form which is disabled by isChanged === false
.
The flow is:
- load from
localStorage
(useEffect) - update form (same useEffect)
- when form changed, set state
isChanged = true
(onChange)
However, it seems that updateInputsWithValue
doesn’t trigger onChange
, so if some changes saved in localStorage
, and is loaded, the button is disabled since isChanged
does not get updated.
Any suggestions?
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
setting input value with JavaScript does not trigger 'onChange ...
In my React app (version 15.4.2), I am updating the value of a text input field with JavaScript - however, I have an...
Read more >Simulate React On-Change On Controlled Components
Manually trigger onChange when component is updated programmatically ... because a “real” browser initiated event doesn't trigger sets on the element.value.
Read more >Primitive input onChange event does not trigger on value ...
Primitive input onChange event does not trigger on value change iOS. complete. Kristian Gerkman. The on change seems to trigger only once, once...
Read more >SCR19: Using an onchange event on a select element ... - W3C
The Applicability section explains the scope of the technique, and the presence of techniques for a specific technology does not imply that the...
Read more >How do I make it so `onChange` doesn't trigger when ... - Reddit
How do I make it so `onChange` doesn't trigger when clicking on an already selected `radio` input? Starting to learn about React and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is the source-code of
updateInputsWithValue
After leaving the problem for 4 months, I think now I can figure out how to implement what I want:
The core of the problem is to determine if
form's currentValue === form's initialValue
===
What I wanted to do 4 months ago was:
Click to expand!
updateInputsWithValue
)===
But since
updateInputsWithValue
doesnot triggeronChange
, I have to manage the form data withuseState
Click to expand!
on page first render
useState(initialValues)
(user profile, for example)the submit button
button is disabled if no changes have been made to the form
on user types
===
Or maybe with
getModel
? (haven’t tried this):===
Or a global
isPristine
as I mentioned in another issueAnyway, this has little to do with
updateInputsWithValue
so I’m closing the issue for now.Thanks for all your supports!!❤️
(Though for me, it feels very intuitive to trigger an
onChange
any time the value of the form changes…🙃)