0

I have a requirement where field value from long text field called Alert_Text_Timeline__c will be displayed as toast message on click of a button.

Below is my code

Component:

<aura:component implements="force:hasRecordId,force:appHostable,flexipage:availableForAllPageTypes">
    <aura:attribute name="record" type="Map" default="{}" />
    <aura:attribute name="disabled" type="Boolean" default="true" />
    <force:recordData targetFields="{!v.record}"
        recordId="{!v.recordId}"
        recordUpdated="{!c.recordLoaded}"
        fields="Alert_Text_Timeline__c" />
    <div>
        <lightning:card>
   &nbsp;&nbsp; <strong><b> Important Alert: </b></strong>  <lightning:button label="Please click here"
                          variant="brand"
                          disabled="{!v.disabled}" 
                          onclick="{!c.showInfo}"/></lightning:card>
        
    </div> 
</aura:component>

JS:

({
    recordLoaded: function(component, event, helper) {
        component.set("v.disabled", false);
    },
    showInfo : function(component, event, helper) {
        var record = component.get("v.record");
        var toastEvent = $A.get("e.force:showToast");
        toastEvent.setParams({
            
            message: record.Alert_Text_Timeline__c,
            duration:' 5000',
            key: 'info_alt',
            type: 'info',
            mode: 'dismissible'           
        });
        toastEvent.fire();
    }
})

Now, I have the text in long text field stored as line by line but when it is rendered as toast message, I'm getting it in a single line.

Is there any way I can display text in toast message line after line or adjust width of toast box so that it will be displayed line after line.

Please suggest

1

Below is the method I used in my component to get line breaks in toast message

<aura:html tag="style">.toastMessage.forceActionsText{white-space : pre-line !important;}</aura:html>

Original comment can be found here.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.