+ Start a Discussion
Santosh Reddy9989Santosh Reddy9989 

event.getSource() was not working

Here's my component code:

<aura:component implements="force:lightningQuickAction,force:hasRecordId" access="global"  >
<ui:inputText aura:id="PlanName" label="Plan Name" required="true" change="{!c.onChange}"/>   
<ui:inputnumber aura:id="Amount" label="Amount" required="true" change="{!c.onChange}" />
<lightning:button label="Add New Card"   aura:id="newcard"    onclick="{!c.chargefun}"  />  
</aura:component >
   
component.js code :

({
 onChange : function(component, event, helper)
    {        
            var selectCmp = event.getSource();
          selectCmp.set("v.errors",null);
    },

chargefun : function(component,event,helper)
{
  var PlanName = component.find("PlanName").get("v.value");
  var amt = component.find("Amount");
  var amount = amt.get("v.value");
   if($A.util.isEmpty(amount) ||  $A.util.isEmpty(PlanName ))
   {
       if ($A.util.isEmpty(amount))
           {
             amt.set("v.errors", [{message:"Please Enter Value"}]);
           }
           if ($A.util.isEmpty(PlanName))
           {
             component.find("PlanName").set("v.errors", [{message:"Please Enter Value..."}]);
           }
   },

})


In above code,  event.getSource() was not working for <ui:inputnumber>. So iam not able to remove error message.
ashu 6112ashu 6112
event.getSource() works on if any event fires such as pressing or clicking a button, changing a value inside input field is not a event.
Santosh Reddy9989Santosh Reddy9989

There is no problem with the event. If I change the value of input field  then change event firing.
 Event. getSource () is working for <ui:inputText>. But it was not working for a <ui:inputnumber>.

Thanks,
Santosh Reddy
Rishabh Rathore 11Rishabh Rathore 11
you can also use onblur event that will work for most of the cases.