How to pass value to another component in lightning?












1














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









share|improve this question





























    1














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









    share|improve this question



























      1












      1








      1







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









      share|improve this question















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






      lightning-aura-components lightning






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 3 hours ago









      Pranay Jaiswal

      13.6k32351




      13.6k32351










      asked 3 hours ago









      user60684

      615




      615






















          1 Answer
          1






          active

          oldest

          votes


















          6














          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"/>






          share|improve this answer

















          • 1




            Omg. Thank you so much! :)
            – user60684
            3 hours ago










          • You're welcome. If this ends up helping, mark the answer as accepted so others can benefit. :)
            – Sebastian Kessel
            3 hours ago











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "459"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f245231%2fhow-to-pass-value-to-another-component-in-lightning%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          6














          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"/>






          share|improve this answer

















          • 1




            Omg. Thank you so much! :)
            – user60684
            3 hours ago










          • You're welcome. If this ends up helping, mark the answer as accepted so others can benefit. :)
            – Sebastian Kessel
            3 hours ago
















          6














          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"/>






          share|improve this answer

















          • 1




            Omg. Thank you so much! :)
            – user60684
            3 hours ago










          • You're welcome. If this ends up helping, mark the answer as accepted so others can benefit. :)
            – Sebastian Kessel
            3 hours ago














          6












          6








          6






          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"/>






          share|improve this answer












          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"/>







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 3 hours ago









          Sebastian Kessel

          8,74552136




          8,74552136








          • 1




            Omg. Thank you so much! :)
            – user60684
            3 hours ago










          • You're welcome. If this ends up helping, mark the answer as accepted so others can benefit. :)
            – Sebastian Kessel
            3 hours ago














          • 1




            Omg. Thank you so much! :)
            – user60684
            3 hours ago










          • You're welcome. If this ends up helping, mark the answer as accepted so others can benefit. :)
            – Sebastian Kessel
            3 hours ago








          1




          1




          Omg. Thank you so much! :)
          – user60684
          3 hours ago




          Omg. Thank you so much! :)
          – user60684
          3 hours ago












          You're welcome. If this ends up helping, mark the answer as accepted so others can benefit. :)
          – Sebastian Kessel
          3 hours ago




          You're welcome. If this ends up helping, mark the answer as accepted so others can benefit. :)
          – Sebastian Kessel
          3 hours ago


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Salesforce Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f245231%2fhow-to-pass-value-to-another-component-in-lightning%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Understanding the information contained in the Deep Space Network XML data?

          Ross-on-Wye

          Eastern Orthodox Church