I’m using the AppSmith forms widget inside a Cordova app, opened with the InAppBrowser plugin. When the user presses the "cancel" or "submit" button, I need to send a message to my app to determine whether to close the opened window. On form submission, I’m calling the following JavaScript function:
export default {
_data: {
event: 'submit'
},
FallbackEvent () {
let message = JSON.stringify(this._data);
postWindowMessage(message, 'window', '*');
},
MessageAppEvent () {
let _targetParentWindow = window?.cordova_iab ??
window?.webkit?.messageHandlers?.cordova_iab ??
window?.opener ??
window?.parent ??
window;
let _message = JSON.stringify(this._data);
_targetParentWindow.postMessage(_message);
},
Button1onClick () {
try {
console.info('Call MessageAppEvent()');
this.MessageAppEvent();
} catch(error) {
console.error('MessageAppEvent failed');
console.error(error);
console.info('Calling FallbackEvent()');
this.FallbackEvent();
}
}
}
The issue is that I’m receiving the following error:
TypeError: Cannot read properties of undefined (reading 'data')
Additionally, when calling from the InAppBrowser context, I need to use window.cordova_iab to properly receive the event. I've tried handling the error by calling FallbackEvent(), but the issue persists.
Could you help me resolve this issue and confirm if my implementation of postMessage is correct?
Thank you in advance for your support.