function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Artem Kalus 7Artem Kalus 7 

Child Lightning Component Runs Attribute Change Event Twice

I am working on a lookup field component. This component will receive a record ID attribute and when ID is changed will query for the record Name.

While working on the lookup field, I found out that the 'aura:handler name="change"...' will execute twice, if used on the child lightning component and the attribute is dynamically updateable from the parent component.

Please see the sample components below. When Neutral button is clicked, the change event is triggered twice.

CMP Screenshot with console logs:
User-added image

Parent CMP:
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes">
         <aura:attribute name="value" type="String"/>
         <c:TestChangeEvent value="{!v.value}"/>
</aura:component>

TestChangeEvent CMP:​​​​​​​
<aura:component controller="Field_Lookup_Ctr">
 
    <aura:attribute name="value" type="String"/>
   
    <aura:handler name="change" value="{!v.value}" action="{!c.valueUpdate}"/>
   
    <lightning:button label="Neutral" title="Neutral action" onclick="{!c.updateAttribute}"/>
   
</aura:component>

TestChangeEvent  CONTROLLER:
({
   
    updateAttribute : function (component, event, helper) {
        component.set('v.value','12345');
    },
    valueUpdate : function (component, event, helper) {
        console.log('valueUpdate()');
    }
   
})

QUESTION:
Can I pause the "Change Event" or make sure it is executed only once, without too much effort?​​​​​​​