How to Pass Data to Lightning Component From Work-Relay Form

User can communicate with lightning component built in to the form via Fire Event form action.

Below example illustrates how to toggle component UI visibility via firing application event.

Add Lightning Component to the form

Add component to fire event (checkbox (1) in example below):

Adding Lightning Component to the form

Create application lightning event.  Add handler to Lightning component

Below test event is named "invoke"and has "displayComponent" attribute which will pass TRUE of FALSE to the lightning component.

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

Below handler and attribute are added to component:  

 <aura:handler event="c:invoke" action="{!c.toggleVisibility}"/>
 <aura:attribute name="display" type="String"/>

Component UI will be displayed on the form if 'display' attribute is set to TRUE:

 <aura:if isTrue="{!v.display == 'TRUE'}"> 
 ... 
 ... 
 
 </aura:if>

toggleVisibility function added to component controller updates 'display' attribute with event 'displayComponent' parameter:

toggleVisibility : function(component, event, helper) {
   component.set("v.display", event.getParam("displayComponent"));
}

Add "Fire event" type action to the form:

  • Populate "Name" field (2) with event name using c:eventName if your organization doesn't have namespace, and namespace:eventName if it does.
  • To pass parameters (3) to application event use event attribute name as a parameter name:

Add event(s) to run Fire Event action

Below is setup of two onChange events tied to the checkbox component.

First event (4) will be fired when checkbox is checked (see event conditions on the screenshot below) and will pass TRUE to the lightning event - this will display lightning component UI on the form.

Second event (5) will be fired when checkbox is unchecked (see event conditions on the screenshot below) and will pass FALSE to the lightning event - this will hide lightning component UI on the form.

0 Comments

Add your comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.