ReCaptcha difficulties in Ember.js component

590 views
Skip to first unread message

Brandon Barrett

unread,
Jan 22, 2015, 3:40:02 PM1/22/15
to reca...@googlegroups.com
The widget works on its own if I use $.getScript('//www.google.com/recaptcha/api.js') after inserting <div class='g-recaptcha' data-sitekey='mykeyhere'></div>

I cannot get the callback to fire for success:
<div class='g-recaptcha' data-callback=myNameSpace.callback data-sitekey='mykeyhere'></div>


and when I go the explicit rendering route I can't get the onload callback to fire:

There are no console errors, and the callbacks don't fire at all.  The callbacks are on the global namespace (not buried in Ember).  For those who know ember, the <div class='g-recaptcha' data-sitekey='mykeyhere'></div> is in a component template, the $.getScript is fired in the didInsertElement hook (after div is inserted), and the callback is on the global namespace.

I don't understand why this isn't working and I'm running out of debug paths to travel down.  Any insights would be greatly appreciated!

Ashraf Hasson

unread,
Mar 11, 2015, 3:26:43 PM3/11/15
to reca...@googlegroups.com
Hi Brandon,

I've done something similar to this, i.e., created a recaptcha component, however, I've not opted for a dynamic load of the api.js script, rather installed it with bower then on `didInsertElement` I just explicitly render the recaptcha, so there's no need for a callback, like so:

export default Ember.Component.extend({
    classNames: ['g-recaptcha''],
    attributeBindings: ['data-sitekey'],
    'data-sitekey': '...',
    didInsertElement: function () {
        var self = this;
        grecaptcha.render(self.$().prop('id'), {
            'sitekey': self.get('data-sitekey')
        });
    }
});


reCaptcha, however, does add an invisible div at the bottom of 'body' which in RTL mode messes up the layout, wonder if you have a cure for that?

Thanks,

Donal Byrne

unread,
Jul 21, 2015, 6:26:49 AM7/21/15
to reca...@googlegroups.com
Could you give an example of how you installed the api.js with bower?

Donal Byrne

unread,
Jul 24, 2015, 8:04:36 AM7/24/15
to reCAPTCHA, byr...@tcd.ie
I got this to work by loading the script with getScript and then waiting for the 'grecaptcha' object to become defined ( the initial script loads a second language-specific script.) 

Gist
Reply all
Reply to author
Forward
0 new messages