Bug: Form reset lost checkbox onChange event
See original GitHub issueHi, I use checkbox uncontrolled mode, onChange in form reset after, lose onChange.
<input type="checkbox" onChange={onChange} />
but use add ref.addEventListener(‘change’, onChange) is ok
const checkRef = useRef<HTMLInputElement>();
useEffect(() => {
if (checkboxRef) {
checkboxRef.current.addEventListener('change', onChange);
}
}, []);
<input type="checkbox" ref="checkboxRef" onChange={onChange} />
React version: 16.13 and old
Steps To Reproduce
- checkbox => checked
- form reset
- checked => checked
Link to code example: not react is ok reset is lose target onChange
The current behavior
- checkbox => checked (target onChange)
- form reset
- checked => checked (lose target onChange)
The expected behavior
- checkbox => checked (target onChange)
- form reset
- checked => checked (target onChange)
Issue Analytics
- State:
- Created 3 years ago
- Reactions:6
- Comments:8
Top Results From Across the Web
148118 – Form-reset triggers superfluous onchange event in ...
KDE Bugtracking System – Bug 148118 Form-reset triggers superfluous onchange event in radiobutton and checkbox Last modified: 2008-10-18 18:39:23 UTC.
Read more >Checkbox onchange event not firing - Stack Overflow
Problem is, when I click on it, the onchange is fired alright, but when I use the first to change it's state, the...
Read more >Event Checkbox onChange missing - Bug - AppGyver forums
Hi @user6, you can create a true/false page variable that you bind to the checkbox value, and then listen to “Page variable changed”...
Read more >Forms in HTML documents - W3C
A control's initial value does not change. Thus, when a form is reset, each control's current value is reset to its initial value....
Read more >Form - Ant Design
Select a option and change input text above. Submit Reset Fill form. Form methods (Class component). We recommend use Form.useForm to create data...
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 Free
Top 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
I’m probably not the right person to review event stuff. Can you make the changes to the source files, then submit a PR?
I wrote a pice of code but I’m not sure if it’s on the right place, did this directly on
react-dom.development.js
.@bvaughn, Is
dispatchEvent
the right place for this kind of actions?