3

I can initialize the value of a lightning:input by doing this:

Component:

<lightning:input aura:id="subject" type="text" label="Subject" name="subject" />

Controller:

component.find("subject").set("v.value", "Hello!");

Result:

enter image description here


However, with lightning:inputRichText, when I follow the same pattern, the UI does not show the value, but if I alert(component.find("body").get("v.value")), it shows the expected value.

Component:

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

Controller:

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

Result:

enter image description here

Can anyone point me in the right direction with this? At the moment, the component documentation doesn't have anything relevant besides listing value as an attribute.

1 Answer 1

2

The below code worked perfectly fine for me

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
 <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
 <lightning:inputRichText aura:id="body" />
</aura:component>

Controller code is as below

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

enter image description here

2
  • 1
    Hm - you're right. I added the component.find("body").set to the init method and it worked just fine. For some reason, it breaks when I have it in a separate method that's called from the parent component, using aura:method....anyway, that is a separate question, and you definitely answered the one that's posted here. I'm going to post a separate question for the specific case that you've helped me narrow it down to. Commented Mar 23, 2017 at 14:07
  • for placement of the update in another method see this answer: salesforce.stackexchange.com/questions/165758/…
    – Bryan
    Commented Jun 12, 2018 at 0:35

You must log in to answer this question.

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