Can't add event listener (key down) after submitting the captcha
See original GitHub issuereact-google-recaptcha version: 1.0.5 react-async-script version: 1.0.1
I render recaptcha in my component
<ReCAPTCHA
sitekey="sadfsdfsadfasdfUqhEHvqxYO4UJeompXDkua"
onChange={this.handleCaptcha}
/>
and want to add the window event listener for Enter key. I want this for accessibility (submitting of form)
componentDidMount() {
window.addEventListener('keydown', function(e) {
console.log(e);
})
}
this is my handleCaptcha method
handleCaptcha = value => {
this.setState({ captcha: value })
}
But the problem is that I can’t catch any event after captcha was submited. I have no idea what to do.
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (5 by maintainers)
Top Results From Across the Web
javascript - addeventlistener for 'keypress' = captcha alternative?
When you say that a bot can't trigger a click event, do you mean that by using an onClick button instead of a...
Read more >add new event handler: initSuccess · Issue #239 - GitHub
I want a new event handler named something like "captcha-successfully-displayed" or "initSuccess". Right now, your api gives us the load ...
Read more >Element: keydown event - Web APIs | MDN
Returns a boolean value that is true if the Shift key was active when the key event was generated. Examples. addEventListener keydown example....
Read more >Keydown is the only keyboard event we need - Mutually Human
Keypress fires after keydown , but still before the browser processes the key (e.g. inserting a character, moving focusing, submitting a form, etc)....
Read more >Adding Google reCAPTCHA to forms
To resolve, create a new reCAPTCHA by clicking the + icon in the top-right corner of your Google reCAPTCHA dashboard and choose reCAPTCHA...
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
@max-glyzin see https://stackoverflow.com/a/22164614/1452289 or https://javascript.info/bubbling-and-capturing#capturing
when you click (or generate any event) on something in a browser, it goes through 2 phases. Capture and Bubbling.
Capture starts from the outer most piece (document / body) and goes through the HTML tree down to your element, letting any handlers do something with the event. When it hits the target element (eg: a button) it starts bubbling back up, using the same route.
Given that capture goes first, you get access to the event before anyone else is able to stop the propagation. If you register on document on the bubbling phase, you will be the last handler to receive the event and thus lets a lot of “time” for other handlers to block the event. By using a document handler on capture phase you are the very first handler to receive the event.
@dozoisch thanks for explanation. Now I understand how this parameter works.