1

I'm using an aura component in a visual force page.

Aura Component: RichInputText.cmp

<aura:component>
    <aura:attribute name="bodyVal" type="String" />
    <!-- Events -->
    <aura:registerEvent name="RichInputTextEvent" type="c:RichInputTextEvent"/>
    <lightning:inputRichText value="{!v.bodyVal}" placeholder="Type something interesting" onblur="{!c.setHtmlBody}"/>
</aura:component>   

Aura Event: RichInputTextEvent.evt

<aura:event type="APPLICATION">
    <aura:attribute name="htmlBody" type="String" default="" access="global"/>
</aura:event>

I'm firing event when rich text box loose focus: RichInputTextController.js

({
    setHtmlBody : function( component, event, helper ){
        var compEvent = component.getEvent("RichInputTextEvent");
        var htmlBody = component.get("v.bodyVal");
        console.log('htmlBodyAura:', htmlBody);
        compEvent.setParams({"htmlBody" : htmlBody });
        compEvent.fire();
    }
})

Aura Application: MultipleEmailLookup.app

<aura:application access="global" extends ="ltng:outApp">
    <aura:dependency resource="c:MultiSelectLookup" />
    <aura:dependency resource="c:RichInputText" />
</aura:application> 

Added handler on vf page:

var vfHandlerForRichTextBox = function(event){
  console.log('htmlBody: ' + event.getParam("htmlBody"));

  $Lightning.use("c:MultipleEmailLookup", function(){
    $Lightning.createComponent("c:RichInputText", {
      bodyVal: emailBody
  }, "rich-text-input", function(){
      $A.eventService.addHandler({ "event": "c:RichInputTextEvent", "handler" : vfHandlerForRichTextBox});
    });
  });

Handler not getting invoke when event fired in aura component.

Update:

I figured out I need to call the application event like this:

$A.get("e.c:RichInputTextEvent");

but now I.m getting this error on my VF page:

This page has an error. You might just need to refresh it. Action failed: c:RichInputText$controller$setHtmlBody [Cannot read properties of undefined (reading 'setParams')] Failing descriptor: {c:RichInputText$controller$setHtmlBody}

I got solution of above error, I need to give global access to the event.

<aura:event type="APPLICATION">
    <aura:attribute name="htmlBody" type="String" default="" access="global"/>
</aura:event>

Now the event is not undefined, but the problem still exists Visualforce handler not invoking.

6
  • Can you try instead of component.getEvent("RichInputTextEvent"); this $A.get("e.c:RichInputTextEvent")?
    – kurunve
    Commented Feb 14, 2023 at 8:29
  • Please my question again I have updated the issue. Commented Feb 14, 2023 at 8:31
  • what is the value of htmlBody comming in your JS controller ?
    – Aman Patil
    Commented Feb 14, 2023 at 8:40
  • It's showing what I type in rich text box. Commented Feb 14, 2023 at 9:42
  • in your vf page console.log('htmlBody: ' + event.getParam("htmlBody")); does this value comes in js console ?
    – Aman Patil
    Commented Feb 14, 2023 at 9:54

1 Answer 1

0

Try defining the handler method separately.

Please change variables name with respect to your component



<apex:page>
    
    <apex:includeLightning />
    <div id="aura-cmp" />
    <script>
    
    function vfHandlerForRichTextBox(event){
        console.log(event.getParam("message"))
    }
    
    $Lightning.use("c:MultipleEmailLookup", function() {
        $Lightning.createComponent("c:RichInputText", {
            bodyVal: emailBody
        }, "rich-text-input", function(){
            $A.eventService.addHandler({ "event": "c:RichInputTextEvent", "handler" : vfHandlerForRichTextBox});
        });
        
    });
    </script>
</apex:page>


11
  • Tried but no success. Is it possible if my application event not firing up. Commented Feb 14, 2023 at 11:22
  • @IbrahimAhmed, I implemented from scratch same as you implemented it works for me i am able to invoke Vf Page handler. can you confirm me what is the error comming, is it the same error as this This page has an error. You might just need to refresh it. Action failed: c:RichInputText$controller$setHtmlBody [Cannot read properties of undefined (reading 'setParams')] Failing descriptor: {c:RichInputText$controller$setHtmlBody} ?
    – Aman Patil
    Commented Feb 14, 2023 at 12:38
  • It occurred before when I didn't give global access to the application event. After adding access="global" to the application event the error was solved but my vf handler still not invokes. Commented Feb 14, 2023 at 12:43
  • @IbrahimAhmed So now no error is comming right but the issue is your vf handler is not getting invoked ? do you see any error in console in JS
    – Aman Patil
    Commented Feb 14, 2023 at 12:45
  • Yes, only handler not getting invoked. No errors on console. Commented Feb 14, 2023 at 12:47

You must log in to answer this question.

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