How to pass value to another component in lightning?
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);
}
})
lightning-aura-components lightning
add a comment |
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);
}
})
lightning-aura-components lightning
add a comment |
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);
}
})
lightning-aura-components lightning
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);
}
})
lightning-aura-components lightning
lightning-aura-components lightning
edited Jan 2 at 18:24
Pranay Jaiswal
14.2k32452
14.2k32452
asked Jan 2 at 18:06
user60684user60684
715
715
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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"/>
1
Omg. Thank you so much! :)
– user60684
Jan 2 at 18:13
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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"/>
1
Omg. Thank you so much! :)
– user60684
Jan 2 at 18:13
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
add a comment |
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"/>
1
Omg. Thank you so much! :)
– user60684
Jan 2 at 18:13
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
add a comment |
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"/>
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"/>
answered Jan 2 at 18:09
Sebastian KesselSebastian Kessel
8,80562136
8,80562136
1
Omg. Thank you so much! :)
– user60684
Jan 2 at 18:13
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
add a comment |
1
Omg. Thank you so much! :)
– user60684
Jan 2 at 18:13
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
1
1
Omg. Thank you so much! :)
– user60684
Jan 2 at 18:13
Omg. Thank you so much! :)
– user60684
Jan 2 at 18:13
You're welcome. If this ends up helping, mark the answer as accepted so others can benefit. :)
– Sebastian Kessel
Jan 2 at 18:13
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
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
@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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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