You need to sign in to do that
Don't have an account?
prasanth sfdc
event not firing in lightning
hi, i am trying to pass the one string value from child component to parent component. but it is not firing. please help me to solve this issue. Thank you.
Child component code: -
Parent component :-
Event:-
Child component code: -
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes" access="global" controller="AccountContactEventClass"> <!-- <aura:registerEvent name="rollUpEventRaja1" type="c.rollUpEventRaja" /> --> <aura:registerEvent name="jaffraja123" type="c:eventraja"/> <aura:handler name="init" value="{!this}" action="{!c.onloadingmethod}" /> <aura:attribute name="contact" type="contact" default="{'sobjectType': 'contact', 'LastName': '', 'Phone': '', 'Title': '', 'AccountId': '' }"/> <aura:attribute name="result" type="string" /> <ui:inputSelect label="Select Account:" class="optionClass" aura:id="InputSelectDynamic" change="{!c.accountSelected}" /> <br/><br/> Insert new contact. LastName: <ui:inputtext value="{!v.contact.LastName}" /> Phone : <Ui:inputtext value="{!v.contact.Phone}" /> Title : <ui:inputtext value="{!v.contact.Title}" /> Department: <ui:inputtext value="{!v.contact.Department}" /> <br/><br/> <ui:button label="Insert contact" press="{!c.insertcontact}" /> ...The reslt is: - {!v.result}..... </aura:component> ({ // Method for displaying the all account names in a picklist value . Loading intially. onloadingmethod :function(component, event, helper) { var apexmeth = component.get("c.callaccounts"); // setting call back. apexmeth.setCallback(this, function(data) { var state = data.getState(); console.log('the state init',state); if(state == "SUCCESS") { var arryRecs =[]; var apexRecs = data.getReturnValue(); for(var i=0;i<apexRecs.length;i++) { var cuurentApexRec = apexRecs[i]; console.log('the rec names are: ',cuurentApexRec.Name); arryRecs.push({"class": "optionClass", label: cuurentApexRec.Name, value: cuurentApexRec.Id}); } var inputsel = component.find("InputSelectDynamic"); inputsel.set("v.options", arryRecs); } else { alert('The state us error while calling the init method'); } }); $A.enqueueAction(apexmeth); }, // Method for inseting new contact with the selected account id from the picklist value. insertcontact : function(component, event, helper) { // calling the value from the component user inputs. var con = component.get("v.contact"); console.log('1st log: '+ con); // calling the apex class method. var apexclass = component.get('c.getcreateContact'); // setting call bank and passing the contact as paramter to the apex class. // con.AccountId = '0012800000zemil'; // Getting the account id selected from the front end user picklist. var selectedAcc = component.find("InputSelectDynamic").get("v.value"); con.AccountId = selectedAcc; apexclass.setParams({ "con" : con }); var ContactInsertedAccount ; apexclass.setCallback(this,function(data){ var state = data.getState(); console.log('the state is : '+state); if(state =="SUCCESS") { console.log('The return val is: ', data.getReturnValue()); component.set("v.result",data.getReturnValue()); ContactInsertedAccount = data.getReturnValue(); } else{ alert('error during calling the callback function'); } }); //adds the server-side action to the queue $A.enqueueAction(apexclass); ContactInsertedAccount ="tesing jaff passing"; var searchCompleteEvent = component.getEvent("rollUpEventRaja1"); /* console.log("event called :"+JSON.stringify(searchCompleteEvent)); var status1 = searchCompleteEvent.setParams({ "accName": ContactInsertedAccount }).fire(); console.log('The stats if fire is : ',status1); */ var searchCompleteEvent = component.getEvent("jaffraja123"); console.log("event called :"+JSON.stringify(searchCompleteEvent)); searchCompleteEvent.setParams({ "variable123": ContactInsertedAccount }).fire(); }, accountSelected : function(component) { var selectedAcc = component.find("InputSelectDynamic").get("v.value"); console.log('the slectesd val is acc : '+selectedAcc); }, })
Parent component :-
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes" access="global" controller="AccountContactEventClass"> <aura:handler name="init" value="{!this}" action="{!c.loadRollUpsummary}" /> <aura:attribute name="accoutRollUps" type="AccountContactEventClass.ReportExample" /> <!-- <aura:handler name="rollUpEventRaja1" event="c:rollUpEventRaja" action="{!c.showAccName}"/> --> <aura:handler name="jaffraja123" event="c:eventraja" action="{!c.myAction}"/> <!-- <ui:outputtext aura:id="accname" /> <ui:outputtext aura:id="rollupcount" /> --> List of Accounts with Rollup contacts count. <table> <tr><td>Name</td><td>Total Contacts</td></tr> <aura:iteration items="{!v.accoutRollUps}" var="acc" > <tr><td>{!acc.accName}</td><td>{!acc.totalContacts}</td></tr> </aura:iteration> </table> </aura:component> ({ loadRollUpsummary :function(component,event) { var apexmeth = component.get("c.rollUpContacts"); apexmeth.setCallback(this,function(data){ var accsData = data.getReturnValue(); console.log('The data is : ',accsData.accName ); component.set("v.accoutRollUps",accsData); }); $A.enqueueAction(apexmeth); }, showAccName : function(component,event) { // component.find("v.accname").set(event.getParam("accName")); console.log('The value of event is: ', event.getParam("variable123")); } })
Event:-
<aura:event type="component" > <aura:attribute name="variable123" type="string" /> </aura:event>