3

I have a <lightning:inputRichText> whose value I can initialize properly like so:

Controller:

init : function(component, event, helper) {
    component.find("body").set("v.value", "<p>This will be init properly once I switch to ContentNote</p>");
}

Component:

<lightning:inputRichText aura:id="body" />

However, if I move the line

component.find("body").set("v.value", "<p>This will be init properly once I switch to ContentNote</p>");

from the init to a different method, the <lightning:inputRichText> value won't be initialized. It's only the <lightning:inputRichText> that's causing a problem.

If I switch the <lightning:inputRichText> to a <lightning:input type="text">, it's initialized fine!

The method follows below, along with the component markup. I stripped it down to the minimum that would reproduce the issue - any help at all would be appreciated.

Method:

showPanel : function(component, event, helper) {
    var overlay = component.find("overlay");
    $A.util.removeClass(overlay, "slds-hide");
    component.find("body").set("v.value", "<p>This will be init properly once I switch to ContentNote</p>");
}

Component:

<aura:component controller="EditOverlayController">
  <lightning:button label="Set InputRichText Value" onclick="{!c.showPanel}"/>

  <div aura:id="overlay" class="slds-hide slds-align--absolute-center" style="position:fixed;width:100%;height:100%;left:0;top:0;background:rgba(51,51,51,0.9);z-index:10;">
      <label class="slds-form-element__label">Body</label>
      <lightning:inputRichText aura:id="body" />
  </div>
</aura:component>
3
  • 1
    FYI @MohithShrivastava, this was the follow-up question Commented Mar 23, 2017 at 14:54
  • I have answered .See if that helps you Commented Mar 23, 2017 at 15:55
  • I think they fixed the problem in the new release v40.
    – Yossi Sud
    Commented May 25, 2017 at 15:54

1 Answer 1

2

Looks like we can override by adding a Renderer file .Here is the code thats working for me

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
 <lightning:button label="Set InputRichText Value" onclick="{!c.showPanel}"/>

  <div aura:id="overlay" class="slds-hide slds-align--absolute-center" style="position:fixed;width:100%;height:100%;left:0;top:0;background:rgba(51,51,51,0.9);z-index:10;">
   <label class="slds-form-element__label">Body</label>
   <lightning:inputRichText aura:id="richTextBody" />
  </div>
</aura:component>

The Js Controller for same is as below

({
  showPanel : function(component, event, helper) {
  var overlay = component.find("overlay");
  $A.util.removeClass(overlay, "slds-hide");
 }
})

The Renderer to make it working is as below

({
render : function(cmp, helper) {
  var ret = this.superRender();
  // do custom rendering here
  cmp.find("richTextBody").set("v.value", "<p>This will be init properly once I switch to ContentNote</p>");
   return ret;
  }
})

Looks like renderer is able to set the value and I fear this is because setting a value on the RichText is manipulating DOM and the component renders after the value is being set so one of the ways to override it using the Renderer file that component framework provides .

5
  • 1
    This worked perfectly. Your explanation on the order of the set and component renders makes sense - thanks very much for your time! Commented Mar 23, 2017 at 16:01
  • 1
    Looks like a issue to me, when I tried same with ui:inputRichText instead of lightning:inputRichText, Brian's code worked fine.
    – Praveen
    Commented Mar 23, 2017 at 18:38
  • @Praveen The ui:inputRichText and lightning:inputRichText are completely different implementations I feel . What I heard is that ui:inputRichText is not locker complaint and had many threats and same with CKeditor that we had before .Looks like under the hood lightning:inputrichtext is implentation of QuillJS library . Commented Mar 23, 2017 at 18:42
  • @MohithShrivastava Yes, you are right. lightning:inputRichText is based on QuillJS. Also i'm sure you know some of the lightning namespaced components have issues. According to me, Brain's code should work despite it is referring to lightning:inputRichText.
    – Praveen
    Commented Mar 23, 2017 at 18:49
  • 1
    Agreed ! It should have been taken care by team that built lightning:inputRichText .Hopefully someone raises a case on this and its tracked Commented Mar 23, 2017 at 18:51

You must log in to answer this question.

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