Skip to content

Instantly share code, notes, and snippets.

@meandavejustice
Created August 2, 2018 17:56
Show Gist options
  • Save meandavejustice/bd8f610788c5a900b316769f8f4780bb to your computer and use it in GitHub Desktop.
Save meandavejustice/bd8f610788c5a900b316769f8f4780bb to your computer and use it in GitHub Desktop.
export default class NewsletterForm extends React.Component {
constructor(props: NewsletterFormProps) {
super(props);
this.handleEmailChange = this.handleEmailChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
componentDidMount () {
if (this.form) {
this.form.addEventListener("submit", this.handleSubmit);
}
}
handleSubmit(evt: Object) {
evt.preventDefault();
evt.stopPropagation();
if (typeof this.props.subscribe !== "undefined") {
this.props.subscribe(this.props.email);
}
}
render() {
return (
<form className={ classnames("newsletter-form", { "newsletter-form-modal": this.props.isModal }) } ref={(el) => this.form = el} data-no-csrf>
{this.renderEmailField()}
{this.renderPrivacyField()}
{this.renderSubmitButton()}
{this.renderDisclaimer()}
</form>
);
}
}
@meandavejustice
Copy link
Author

Since moving to adding the event listener to actual element via ref:

Content Security Policy: The page’s settings blocked the loading of a resource at https://example.com:8000/ (“form-action”).
[Show/hide message details.] XHRPOST
https://basket.mozilla.org/news/subscribe/

When using the react's built in onSubmit listener, I get the error after the https://basket.mozilla.org/news/subscribe/ log

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment