question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't add event listener (key down) after submitting the captcha

See original GitHub issue

react-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:closed
  • Created 4 years ago
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
dozoischcommented, May 7, 2019

@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.

0reactions
max-glyzincommented, May 9, 2019

@dozoisch thanks for explanation. Now I understand how this parameter works.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found