1

Lightning component

<aura:handler event="c:SVC_SearchOnKeyChange" action="{!c.searchTabChange}"/>
<ui:inputText aura:id="caseSubject" class="slds-input" value="{!v.Case.Subject}" change="{!c.searchKeyChange}" updateOn="change" required="true"/>
<ui:inputTextArea aura:id="caseDescription" class="slds-input" value="{!v.Case.Description}" required="true"/>

Controller.JS

//Value of Event
searchKeyChange: function(component, event, helper) {
   var myEvent = $A.get("e.c:SVC_SearchOnKeyChange");
   myEvent.setParams({"searchKey": event.getSource().get("v.value")});
   myEvent.fire();
},

// Results of value on tab change of subject and description field
searchTabChange: function(component, event) {
   var source = event.getSource().getElement();
   console.log(source);
   var classN = source.ClassName;
   var searchKey = event.getParam("searchKey");
   var action = component.get("c.fetchArticlesBySubject");
   action.setParams({
     "searchKey": searchKey
   });
   action.setCallback(this, function(a) {
       component.set("v.articles", a.getReturnValue());
   });
   $A.enqueueAction(action);
}

Want to define action according to subject or description with single function.enter code here

2
  • You can specify a name when you add your handler and event register. I never tried that but I suppose that you can handle the same event with different names specified. Commented Jul 28, 2017 at 10:09
  • We can use event.getSource().getLocalId(); which gives id of field who triggered event and accordingly we can call different method of apex controller Commented Jul 28, 2017 at 10:18

1 Answer 1

0
event.getSource().getLocalId();

Use above which gives id of field who triggered event and accordingly we can call different method of apex controller. In my case it returns caseSubject or caseDescription

You must log in to answer this question.

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