0

I am trying to trigger events in force:inputfield which is binded by Sobject lookup.How to identify value change of the field.I tried in two approach:

 <aura:registerEvent name="testEventFired" type="c:testevent"/>
 <aura:handler name="testEventFired" event="c:testevent" action="{!c.func}"/>
 <force:inputfield aura:id="Name" value="{!v.objectfieldbinding}" change="{!e.testEventFired}"/>
  testevent is component event
  2:
 <force:inputfield aura:id="Name" value="{!v.objectfieldbinding}"/>
   <aura:handler name="change" value="{!v.name}" action="{!c.func}"/>`

func will trigger a another component event in controller side.I cant able to bind the value of inputfield in handler beacause it is not attribute value

NewEdit: To brief you on the context more I am trying display table with team member based on the account selected in the component my code is here below:

<aura:registerEvent name="componentEventFired" type="c:Callevent"/>
<aura:attribute name="obj" type="csutomobjecttype" default="{ 'sobjectType': 'customobject' }"/>
<force:inputfield aura:id="Account" value="{!v.obj.Accountlookupfield}" change="{!c.evac}"/>
<aura:handler name="componentEventFired" event="c:Callevent" action="{!c.trigaction}"/>
event:
<aura:event type="Component" description="Event template">
<aura:attribute name="display" type="object"/>
</aura:event>
controller Js:
evac: function(component,event)
          {
            var  evva=component.find("Account").get("v.value");
            var compEvents = component.getEvent("componentEventFired");
            compEvents.setParams({ "display" : evva });
            compEvents.fire();

           },
        trigaction : function(component, event) {
        var context = event.getParam("display");
        var atmaction=component.get("c.getatm");
        atmaction.setParams({
            atr : context
        });
           atmaction.setCallback(this,function(a){
            //get the response state
            var state = a.getState();
            //check if result is successfull
            if(state == "SUCCESS"){
                component.set("v.at",a.getReturnValue());
                component.set("v.edit",true);
                alert('Success');
            } else if(state == "ERROR"){
                alert('Error in calling server side action');
            }
        }); 
        $A.enqueueAction(atmaction);
      }
})
Apex class:
public Id atr {get;set;}
@AuraEnabled
Public static List<AccountTeammember> getatm(string atr){
            List<AccountTeammember> atm = new List<AccountTeammember>();
            atm=[SELECT TeamMemberRole,UserId FROM AccountTeamMember where AccountId =:atr ];  
    return atm;
    }
}
  • So why we need the event for that, can't we simply move this trigaction controller method to helper and call it from evac? that seems easy to me. – itzmukeshy7 Oct 6 '20 at 2:12
0

Add change attribute which points to a controller method in the force:inputField component.

myApp.app:

<aura:application controller="AccountController" extends="force:slds">
   <aura:attribute name="contact" type="Contact" 
               default="{ 'sobjectType': 'Contact' }"/>
   <force:inputField aura:id="accountLookup" 
                 value="{!v.contact.AccountId}" change="{!c.inputChanged}"/> 
</aura:application>

myAppController.js:

({
    inputChanged : function(cmp, event, helper) {
        console.log('changed')
    },
})

FYI, force:inputField is noisy at the moment, you might get some weird errors while using it.

  • inputfield is getting disabled after added fuction to the change attribute.See my edited code above – Vidhyasagaran Muralidharan Jan 6 '17 at 19:08

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.