0

Is it possible to display a warning toast event msg whenever a component is created?

Basically, without triggering it in any way, like with a btn click.

.js

showMsg(){
 const evt = new ShowToastEvent({
  title: 'Toast Warning',
  message: 'Warning!',
  variant: 'warning',
  mode: 'sticky'
 });
 this.dispatchEvent(evt);
}

.html

<div class="warning" onnotification={showMsg}></div> 

'Cause right now it obviously isn't working.

If not with an event, how can I achieve that? (Trying to avoid custom css)

3
  • Did you try calling this.showMsg() from the connectedCallback on your LWC?
    – Phil W
    Commented May 10, 2021 at 10:35
  • @PhilW Just did, nothing happens. Commented May 10, 2021 at 10:52
  • @samdev Yep, it is imported. I dunno why it doesn't work with connectedCallback, I tried renderedCallback as well since this is a child component and gets fired from the parent on certain conditions. But anyway, I figured now I'll just use slds-notify and get it done get it over with :) Thanks for your time both of you. Commented May 10, 2021 at 11:25

1 Answer 1

0

By the way, my bad, I am using this component embedded in a VF page through an aura wrapper app so what I was trying to do wouldn't work. I will make it work with slds-notify instead.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .