I have a form where the user sees a product, discount, and a total price. The total price is calculated from the list price, and the discount is defaulted to 0. enter image description here

The requirement is that the user can provide a discount (f.ex. 50%) -> so total price gets updated; or the user can also provide directly the total price -> the discount is derived from that.

I used two handlers for those 2 fields, but if I update any of them -> the update gets stuck in a loop, and the fields get locked, i.e. I cannot edit them.

I believe it has to do something with event bubbling. Do you have any suggestions? Thanks!

  • Can you edit your question to include the handlers you reference so we can see how you're updating these fields?
    – David Reed
    Jul 16 '18 at 16:17

Yes, because of how Lightning works, the change handler will result in infinite events firing back and forth between the two handlers. You'll probably want to ignore the next event, like this:

<aura:attribute name="ignoreUpdateEvent" type="Boolean" default="false" />


if(!component.get("v.ignoreUpdateEvent")) {
  component.set("v.ignoreUpdateEvent", true);
} else {
  component.set("v.ignoreUpdateEvent", false);

This will make sure that you won't cause an infinite event loop.

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.