Skip to content

Instantly share code, notes, and snippets.

@sbutterfield
Created October 29, 2020 03:02
Show Gist options
  • Save sbutterfield/c2938ba91c577aebd212d224e18ccb1b to your computer and use it in GitHub Desktop.
Save sbutterfield/c2938ba91c577aebd212d224e18ccb1b to your computer and use it in GitHub Desktop.
IFrameLWCFlowAttributeChangeEvent.js The LWC has an embedded iFrame. I believe that the listenForMessage() reference window.addEventListener() call in my connectedCallback() is really within the this context of the iFrame, not the LWC. Therefore, when I set a value in that callback, I'm setting a different value than the one in the LWC. Which is…
import { LightningElement, api, track } from 'lwc';
import { FlowAttributeChangeEvent } from 'lightning/flowSupport';
import pageUrl from '@salesforce/resourceUrl/recaptcha2';
export default class GoogleCapatcha extends LightningElement {
navigateTo;
@api result = "undefined";
connectedCallback(){
var self = this;
this.navigateTo = pageUrl;
window.addEventListener("message", function(message) {
self.result = (message.data === "captcha success") ? "true" : "false";
self.dispatchEvent(new FlowAttributeChangeEvent('result', self.result));
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment