Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting error when recaptcha is not rendered #68

Closed
rohitsodhia opened this issue Oct 13, 2017 · 11 comments
Closed

Getting error when recaptcha is not rendered #68

rohitsodhia opened this issue Oct 13, 2017 · 11 comments
Labels

Comments

@rohitsodhia
Copy link

I have a recaptcha in a div that's hidden until I need the form. I'm using a *ngIf to show or not show the form. When the default state is shown, no problem. When the default state is hidden, instead, I get:

ReCAPTCHA placeholder element must be an element or id

Admittedly, I'm not great at debugging JS, but I tried searching online for what may be an issue, and couldn't find anything. I'm hoping you may be able to help me figure out where I may have gone wrong? Given nothing's rendered yet, I'm confused why it'd be trying to place one?

@rohitsodhia rohitsodhia changed the title Getting error when recaptcha is hidden Getting error when recaptcha is not rendered Oct 13, 2017
@dockleryxk
Copy link
Contributor

I'm not sure exactly why this might be, but have you tried using [hidden] or setting the style of the div to display:none in the component.ts based on your variable you're using in your *ngIf? That's what I would do

@rohitsodhia
Copy link
Author

rohitsodhia commented Oct 13, 2017 via email

@rohitsodhia
Copy link
Author

So I realized I can't use hidden in my code without it causing other issues, but I've been trying to debug, and what I'm seeing is that even though the parent of the parent containing the ng-recaptcha component isn't being rendered (via the *ngIf), ngAfterViewInit is still firing, causing renderRecaptcha to fire, and failing, because there is no ng-recaptcha component in the view, and thus it never got the id to add the recaptcha to.

I'm not really all that experienced, but if the component isn't yet in the view (thanks to something like *ngIf, shouldn't ngAfterViewInit not fire?

@DethAriel
Copy link
Owner

Thank you for submitting this, @rohitsodhia , and for doing initial triaging! I've tried to reproduce this error in plunker (see here), but my attempt was unsuccessful. Could it be that there is something else in your scenario, that is different from this example?

@rohitsodhia
Copy link
Author

Looking at that plunker vs what I have, I see it's because I have code separated into modules. I noticed that in the readme, there is a link saying more information on modules later, though it doesn't go anywhere. I created a quick repo reproducing the error in a clean environment. I'm hoping that it's just a case of me not using your project correctly or perhaps something about Angular I don't yet understand. Admittedly, I tried to download and debug the package myself to get into the open source community, but alas, tis not so.

@DethAriel
Copy link
Owner

@rohitsodhia sorry for not responding for a while. Were you able to resolve this issue?

@rohitsodhia
Copy link
Author

No problem. And no, I wasn't. After making the repo I linked above, I ended up working on a different feature and haven't been back to this since.

@brgaulin
Copy link

brgaulin commented Nov 20, 2017

I'm also seeing this error where I'm using component factory to create a component(works ok) then if I destroy that component, and make it again later(probably being reused?) I get the ReCAPTCHA placeholder element must be an element or id error. Its a bit cumbersome to reproduce in plunkr, but I'll see if I can dig something up =)

Update: Most Likely unrelated my bug, and my own doing. It looks in my component factory, angular is creating the component before putting anything in the DOM, and since the element isn't in the document, well, I get the error that it isn't there.

@brgaulin
Copy link

After poking around for a bit, without brute forcing it(try catch then break when we actually render), not sure if there is a good way out in my scenario. Angular(4) appears to be rendering my DOM internally, and then appending it to the real DOM, which will never work. And I'm assuming you are stuck in a similar issue, where, with the subcomponent that way the modal renders the stuff and then hides it, then triggers the afterViewInit.

@DethAriel
Copy link
Owner

@rohitsodhia @brgaulin looks like this issue will be solved by #77 (tested in locally and with the example provided by @rohitsodhia ).

@brgaulin
Copy link

Looks good. To follow up. My bug was how I was rendering the captcha.

I was creating the component with a factory. Then adding it to a view. When I inverted this so that the parent component created it. It was much happier.

This commit also looks great!

Thanks for the follow up!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants