You can accomplish this using jquery to change the css of the toast component.
Add this line before your toast
$('.forceToastManager').css('white-space', 'pre-wrap');
Then just add \n
's wherever you want line breaks in your message. In your case you can replace .
with \n
and I believe it will work as you want.
No, a toast is an informative message (e.g. an error occurred or something else). It is not a modal dialog with buttons you can configure. You'll notice that there's absolutely no way to know that a toast has even been closed/dismissed, much less know the disposition of that closure.
The correct method would be to use the lightning:overlayLibrary (or create your own modal dialog). How it works is given in the documentation. First, you include overlay library:
<lightning:overlayLibrary aura:id="overlayLib"/>
And then you call it when you need it:
var modalBody;
$A.createComponent("c:modalContent", {},
function(content, status) {
if (status === "SUCCESS") {
modalBody = content;
component.find('overlayLib').showCustomModal({
header: "Application Confirmation",
body: modalBody,
showCloseButton: true,
cssClass: "mymodal",
closeCallback: function() {
alert('You closed the alert!');
}
})
}
});
Where c:modalContent
is the thing you want to show in the modal dialog. I suggest you read the documentation for more information.
Further down, they demonstrate a OK/Cancel dialog. It's kind of complicated, so I won't reproduce it here, but basically you create a custom footer component that has the buttons to show and a custom modal component for the body to show.
Best Answer
For Multiple Lines Toast in LWC
we have to override CSS :
File Content :
.toastMessage{
}
import { loadStyle } from 'lightning/platformResourceLoader';
import CUSTOMCSS from '@salesforce/resourceUrl/{yourfileName}';
a) Define variable like : isCssLoaded = false;
renderedCallback(){
}
4)Create your toast message like this :
var msg = 'This is first-line \nThis is Second Line. \nThis is the third Line.';
const evt = new ShowToastEvent({