0

I want to use these dialog-samples in my project. I downloaded js and css files, packed into zip and uploaded as static-resource. Trying to use it, I receive ReferenceError: Dialog is not defined. How can I solve this?

sharingSettings.js

import dialog from '@salesforce/resourceUrl/dialog';

export default class SharingSettings extends LightningElement {

   async connectedCallback() {
      this.loadScripts();
   }

   async loadScripts() {
      try {
           await loadScript(this, dialog + '/dialog.js');
           console.log('scripts loaded');
      } catch (error) {
           console.error(error);
           throw new Error('error loading scripts ', error)
      }
   }

   async handleShowAlert() {
      await Dialog.alert(
          'Message',
          {ok: 'OK'}
      );
   }
}

dialog.js


let Dialog = (() => {

// Ommited for brevity

    // expose the external API to the caller/user of this code
    return {
        
        alert(message, opts, cb) {
            return new AlertDialog(message, opts, cb).open();
        },

        
        confirm(message, opts, cb) {
            return new ConfirmDialog(message, opts, cb).open();
        },

        
        prompt(message, opts, cb, defaultValue) {
            return new PromptDialog(message, opts, cb, defaultValue).open();
        }
    }

})();
2
  • 1
    Yes, I know the linked questions are about Luxon and YouTube, but the solution is the same.😁
    – sfdcfox
    Commented Jun 2, 2022 at 23:56
  • Changing let Dialog = to window.Dialog = did the work, thank you :) Commented Jun 3, 2022 at 6:00

0

Browse other questions tagged .