My goal is to check if the user really changed the value in the input field.
In visualforce, I do this by storing the old value in HTML5 data attributes and onchange event compare the old value with the new value to see if it really changed:
<apex:inputField value="{!oppObj.field1__c}"
html-data-oldValue="{!oppObj.field1__c}">
</apex:inputField
But I am confused as how to do the same in lightning components as these are not supporting html5 data attributes. I have code something like this and it is not taking html5 data attributes.
<ui:inputNumber aura:id="someFld"
class="slds-input"
value="{!oppObj.field1__c}"
change="{!c.fieldChanged}">
</ui:inputNumber>
Any help on this?
EDIT:
I have ui:inputNumber inside the aura:iteration tag, so it is like this:
<aura:iteration items="{!v.oppList}"
var="oppObj"
indexVar="i">
<ui:inputNumber aura:id="{!i + '_someFld'}"
class="slds-input"
value="{!oppObj.field1__c}">
</ui:inputNumber>
</aura:iteration>
As suggested, I am trying to define <aura:handler name="change"../>
inside aura:iteration
but it throws this error :
Failed to save undefined: markup://c:TestComponent:231,67:
Invalid attribute "name": Source
Best Answer
You could use a handler for that.
Add this to your component:
v.value
= aura:attributec.valueChanged
= method in your lightning controllerThen your
ui:input
would be like so:Example here.