3

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>
    &nbsp;&nbsp;&nbsp;&nbsp;

    <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);
}
})
7

Your aura:handler tag has action="act", when it should be action="{!c.act}". Don't forget that it has to point to a controller action.

Also, on your declaration, you're using a period instead of a semicolon. Change this <aura:registerEvent name="formSubmit" type="c.FormSubmit"/> to this <aura:registerEvent name="formSubmit" type="c:FormSubmit"/>

  • You're welcome. If this ends up helping, mark the answer as accepted so others can benefit. :) – Sebastian Kessel Jan 2 at 18:13
  • 1
    @user60684 If this answer addressed your problem, please consider accepting it by clicking on the check mark/tick to the left of the answer, turning it green. This marks the question as resolved to your satisfaction, and awards reputation both to you and the person who answered. If you have >= 15 reputation points, you may also upvote the answer if you wish. There is no obligation to do either. – Adrian Larson Jan 3 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.