In a Salesforce Aura (Lightning) Component, when an <aura:attribute> is bound to a <lightning:input> component's value attribute, there are two ways to listen for changes to the input. Only one method — using the onchange attribute directly on <lightning:input> — allows you to modify the input value in your controller code using component.set(). Using an <aura:handler> for the change event blocks the use of component.set() to prevent input validation errors from occurring.
This approach uses <aura:handler name="change"> to listen for changes to an <aura:attribute>. While it detects changes, it blocks the use of component.set() in the controller. This means you cannot programmatically reset or modify the input value. For example, if the user types "foo" into a number field, calling component.set() to reset the value to an empty string will not work with this approach. This restriction is enforced to prevent errors such as validation loops.
Incorrect Example:
The following code listens for a value change on the attribute "myValue" using <aura:handler>. In the controller's handleChange function, calling component.set("{!v.myValue}", "New text") will NOT update the input field to "New text":
<aura:attribute name="myValue" type="String">
<aura:handler name="change" value="{!v.myValue}" action="{!c.handleChange}" />
<lightning:input type="text" name="textInput" label="Enter some text" value="{!v.myValue}" />
Use the onchange attribute directly on <lightning:input>. This allows your controller's handleChange function to use component.set("{!v.myValue}", "New text") to successfully update the input value and trigger the appropriate validation behavior.
Correct Example:
The following code uses the onchange attribute on <lightning:input>. In the controller's handleChange function, component.set("{!v.myValue}", "New text") will successfully set myValue to "New text":
<aura:attribute name="myValue" type="String">
<lightning:input type="text" name="textInput" label="Enter some text" value="{!v.myValue}" onchange="{!c.handleChange}" />
For more information, refer to the documentation on the Aura Component lightning:input.
000380517

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.