I try to use event with type="APPLICATION" in my superbadge step, but can't to get the result even from the simple second component.
I need to get my boat's Id when I press "Search" button. In both alerts I get it. But not in the second component. What is wrong here?
FormSubmit.evt:
<aura:event type="APPLICATION">
<aura:attribute name="eventAttribute" type="String"/>
</aura:event>
BoatSearchForm.cmp:
<aura:component controller="BoatSearchFormApex" implements="force:appHostable,flexipage:availableForAllPageTypes" access="global" >
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<aura:registerEvent name="formSubmit" type="c.FormSubmit"/>
<aura:attribute name="types" type='String[]' default='All'/>
<aura:attribute name="showNewButton" type="Boolean" default="true"/>
<lightning:layout horizontalAlign="center" verticalAlign="end" class="layoutClass">
<lightning:select aura:id="types" name="types" variant="label-hidden" label="">
<option value="allTypesValue">All Types</option>
<aura:iteration items="{!v.types}" var="type">
<option value="{!type.Id}">{!type.Name}</option>
</aura:iteration>
</lightning:select>
<lightning:button variant="brand" label="Search" onclick="{!c.onFormSubmit}"/>
<aura:if isTrue="{!v.showNewButton}">
<lightning:button variant="neutral" label="New" onclick="{!c.newBoat}"/>
</aura:if>
</lightning:layout>
Function in controller:
({
onFormSubmit : function(component, event, helper){
var typeId = component.find("types").get("v.value");
alert(typeId);
var formSubmit = $A.get("e.c:FormSubmit");
formSubmit.setParams({"eventAttribute" : typeId})
var test = formSubmit.getParam("eventAttribute");
alert(test);
formSubmit.fire();
},
})
cmp2 for test:
<aura:component >
<aura:attribute name="Get" type="String"/>
<aura:handler event="c:FormSubmit" action="act"/>
The result is {!v.Get}
</aura:component>
cmp2Controller.js:
({
act : function(component, event, helper) {
var show = event.getParam("eventAttribute");
component.set("v.Get", show);
}
})