+ Start a Discussion
LinThawLinThaw 

Show message with multiple lines using showToast

Hi there,
I want to use showToast and
show message with multiple lines.
I tried as follow but \n is not working well.
({
    fireToastEvent : function(component, event, helper) {
        var toastEvent = $A.get("e.force:showToast");    
        toastEvent.setParams({
            "title": "Title",
            "message": "This is line 1. \n This is line 2. \n This is line 3.",
            "type": "success"
        });
        toastEvent.fire();
    }
})
is there any idea?

Regards,
LinThaw
 
Best Answer chosen by LinThaw

All Answers

GauravGargGauravGarg

Hi Lin,

Please try <br> insted of \n. This might help else need to Javascript coding. 

Thanks,

Gaurav
Skype: gaurav62990

LinThawLinThaw
Thanks GauravGarg,
I tried <br> also.
But not going to new line.
Regards,
LinThaw
LinThawLinThaw
Thanks GauravGarg,
I also try that way.
I think line break is not working for message of showToast.
Regards,
LinThaw
sfdcMonkey.comsfdcMonkey.com
This was selected as the best answer
LinThawLinThaw
Thanks you Piyush,
Nice override way.
Regards,
LinThaw
Madhankumar VisvakumarMadhankumar Visvakumar
Hi LinThaw,
This can also be achieved by this method which will be very simple. Just add the below mentioned code in your component.
Component:
<aura:html tag="style">.toastMessage.forceActionsText{
white-space : pre-line !important;
}</aura:html>

And In the message put  "\n" in the place you want new line.
Example.js:
({
    fireToastEvent : function(component, event, helper) {
        var toastEvent = $A.get("e.force:showToast");    
        toastEvent.setParams({
            "title": "Title",
            "message": "This is line 1. \n This is line 2. \n This is line 3.",
            "type": "success"
        });
        toastEvent.fire();
    }
})

Hope this helps for new Lightning developers.

Thanks,
Madhan

 
satya Vishwakarmasatya Vishwakarma
Thanks Piyush. It works.