CMeldgaard / Silverstripe-Recaptcha

MIT License
4 stars 3 forks source link

JS doesn't work when extending RecaptchaForm #1

Closed acndr closed 5 years ago

acndr commented 5 years ago

When implementing this module into my project I've found that it doesn't work when my form extends RecaptchaForm. I have a lot of functionality in my form so I typically extend the form and contain the functionality in there instead of the controller, like so:

class CustomForm extends Form
{
   ....
}

However when applying the same to this module, like this:

class CustomForm extends RecaptchaForm
{
   ....
}

I get a javascript error Cannot read property 'addEventListener' of null. This is due to the fact the event listener is bound to getElementById('RecaptchaForm_'+'ContactForm') which is hard coded to assume the form class will be RecaptchaForm . However as I've extended this class it would need to account for the new class name - in this case CustomForm_.

Can you extend this module to account for the class name?

CMeldgaard commented 5 years ago

Should be possible to optimize the javascript to take into account that the name can Change.

acndr commented 5 years ago

@CMeldgaard I'v created a pull request for this

CMeldgaard commented 5 years ago

Fixed with pullrequest #3

New release has been created: 0.1.5