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.

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

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

  calculateOpptyValue(); //Call functions here
| improve this answer | |
  • 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 Oct 3 '16 at 13:59
  • You can handle that using some boolean variable as when to call the function. – Krishna Bidwai Oct 3 '16 at 14:14
  • Or use two handlers – Caspar Harmer Aug 21 '18 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. – Matthew Souther Jun 3 '19 at 21:10
  • @Raj_SFDC let us know if this was helpful to you. – Krishna Bidwai Jun 7 '19 at 23:12

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

in your controller function :

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

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?

| improve this answer | |

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.