3

Trying to rewrite an aura component that loads an email template into a rich text field but the field does not update. The tracked value updates as I can see it if I output it.

<lightning-combobox
    name="templateSelect"
    label="Select Email Template"
    value={emailTemplate}
    placeholder="Select Template"
    options={emailTemplates}
    onchange={changeEmailTemplate} >
</lightning-combobox>

<div class="slds-form-element__control">
    <lightning-input-rich-text aura:id="body" value={emailContents.data}></lightning-input-rich-text>
       {emailContents.data}
</div>

JS FILE:

import { LightningElement, api, track, wire } from 'lwc';
import getEmailTemplateContents from '@salesforce/apex/REMOVED_FOR_POST .loadEmailTemplate';
const DELAY = 300;
export default class REMOVED_FOR_POST extends LightningElement {
  @api recordId;

  @track openmodel = false;
  @track emailTemplate = '...';
  @track emailContents;
  @track error;

  @wire(getEmailTemplateContents, {leadID: '$recordId', template: '$emailTemplate'}) emailContents;

  get emailTemplates() {
    return [
        ...
    ];
  }
    openmodal() {
        this.openmodel = true
    }
    closeModal() {
        this.openmodel = false
    } 
    emailResults() {
      alert("email");
    }
    changeEmailTemplate(event) {
      const value = event.target.value;
        this.delayTimeout = setTimeout(() => {
            this.emailTemplate = value;
        }, DELAY);
    }
}

APEX

@AuraEnabled(cacheable=true)
    public static string loadEmailTemplate(Id leadID, String template){

        Lead ld = [SELECT Id, Name, Program_Requested__c, Branch_Parent_Account__r.Name, Branch_Account__r.Type_to_Branch__c, Email, Loan_Officer_Contact__r.Name, Owner.Email, Owner.Phone,Owner.Name, Owner.Title
            FROM Lead
            WHERE Id= :leadID];

        QQ_Email_Template__c et = [SELECT Id, Email_Body__c FROM QQ_Email_Template__c WHERE Name= :template];
        String htmlBody = et.Email_Body__c;


        htmlBody = htmlBody.replace('{{LEAD_LOAN_OFFICER_CONTACT_NAME}}', ld.Loan_Officer_Contact__r.Name);

        htmlBody = htmlBody.replace('{{LEAD_BORROWER_NAME}}', ld.Name);
        htmlBody = htmlBody.replace('{{LEADOWNER_PHONE}}', ld.Owner.Phone);
        htmlBody = htmlBody.replace('{{LEADOWNER_EMAIL}}', ld.Owner.Email);
        htmlBody = htmlBody.replace('{{LEADOWNER_FULLNAME}}', ld.Owner.Name);
        htmlBody = htmlBody.replace('{{LEADOWNER_TITLE}}', ld.Owner.Title);
        return htmlBody;
    }

It works fine until I put it as the value of the lightning-input-rich-text.

2
  • Could you add the apex controller class you are using ? Jun 8, 2019 at 20:11
  • 3
    It works, but only after I bring the field into focus by clicking the rich text area. On first change, nothing happens, but if I click inside the rich text area, it will update the data. After that initial click into the field, it updates instantly on dropdown change.
    – BillyB
    Jun 9, 2019 at 2:23

1 Answer 1

1

Can you try to focus the lightning input rich text on change of email template this.template.querySelector('lightning-input-rich-text').focus(); this.template.querySelector('lightning-input-rich-text').blur();

1
  • Thanks. This worked great.
    – BillyB
    Aug 8, 2019 at 16:31

You must log in to answer this question.

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