0

i need to call two functions at same time from change attribute in input checkbox component.

I have two function, one is generic(Say SaveFunction) and another function(do some calculation). i tried one way as binding expression such

{!c.saveFunction + c.calculateOpptyValue} 

the above code didnt work and i know another workaround calling another help in generic function , but i dont want implement any unnecessary logic in generic function.

Please let me know how can i do first way in calling the multiple functions.

2
  • I don't think, we can do it. Commented Oct 3, 2016 at 14:14
  • Using helper is the only way to do it.
    – Praveen
    Commented Oct 3, 2016 at 16:53

2 Answers 2

1

You can call c.calculateOpptyValue from the c.saveFunction funtion Example:

c.saveFunction(){
  console.log('===');
  calculateOpptyValue(); //Call functions here
} 
5
  • My question is different here, i am using same c.savefunction for multiple components , but i want c.calculateOpptyValue for only one component. so as per your logic it call for all components events wherever i used autosave function, rather than i need use calculateOpptyValue function only one component along with savefunction.
    – Raj_SFDC
    Commented Oct 3, 2016 at 13:59
  • You can handle that using some boolean variable as when to call the function. Commented Oct 3, 2016 at 14:14
  • Or use two handlers Commented Aug 21, 2018 at 1:24
  • Option 1: Use the reverse of Krishna's approach and call saveFunction from calculateOpptyValue. Option 2: Put functions you want to reuse in the helper, and use the controller exclusively for handling events. Commented Jun 3, 2019 at 21:10
  • @Raj_SFDC let us know if this was helpful to you. Commented Jun 7, 2019 at 23:12
0

Just to extend the idea of @Krishna Bidwai , If you need to call c.calculateOpptyValue from c.savefunction for only one button, below approach can be used :

On your button add a div with an attribute such as

<div onclick="{!c.savefunction }" data-value="abc">
    <lightning:button label="Save" iconPosition="left" value="123"/>
</div>

in your controller function :

   savefunction  : function(component, event, helper) {
        var currentEvt = event.currentTarget;
        var data_Value = currentEvt.dataset.value;
        console.log(data_Value);
    if(data_Value == 'abc'){
    calculateOpptyValue();
    }
}

For more information on above technique , refer below answer from @Caspar Harmer: What is the correct way to pass Parameters to Lightning JS controller from UI:Button?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .