2

This question already has an answer here:

I'm changing a field in my lightning component and handle the change with a default lightning change handler. I can not make use of aura:handler name="change" since I'm in a loop, where change events are not fired (already created an issue)

<aura:iteration items="{!v.values}" var="value">
    <ui:inputNumber change="{!c.numberChanged}" value="{!value}" />
</aura:iteration>

In my controller I'm now trying to handle that change. But to do so, I need the the old field value. Is there anything in the retrieved event object, that contains this information? I digged deeper into the event methods and tried to output whatever I found, but there was nothing useful. Is the event technology documented somewhere in detail?

numberChanged: function(cmp, evt, helper) {
    console.log(evt.getEventType());
    console.log(evt.getType());
    console.log(evt.getName());
    console.log(evt.getPhase());

    console.log(evt.getSource());
    console.log(evt.getSource().getEvent());
    console.log(evt.getSource().toString());
},

Output:

  • COMPONENT
  • ui:change
  • change
  • bubble
  • -
  • [Object with a few methods]
  • null
  • SecureComponentRef: markup://ui:inputSmartNumber {3765:949;a}{ key: {"namespace":"MY_NAMESPACE"} }

3765:949 seems to be an internal identifier, it's not the numbers I changed.


EDIT1: since I found this guide, it feels like there is more information behind the getSource(), but where is it documented?


EDIT2: Added more information to make clear why <aura:handler name="change" ...> won'work

marked as duplicate by Martin Lezer, battery.cord, glls, Raul, Santanu Boral Sep 27 '17 at 15:56

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

The below link details on how to capture old and new values.

Lightning Change Event

So we access the values in the controller as follows:

({
    numberChanged : function(component, event, helper) {
        var newValue = event.getParam("value");
        var oldValue = event.getParam("oldValue");
        alert("Expense name changed from '" + oldValue + "' to '" + newValue + "'");
    }
})
  • This is a link only answer which is better suited as a comment as per How to Answer, please elaborate on the answer, since links can change. – glls Sep 27 '17 at 13:04
  • as mentioned it's a good answer, thanks you! but it doesn't work for me, I updated the question. – Basti Sep 27 '17 at 13:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.