Say I have quantity, price, discount and total field. What I want to do is dynamically update the total field on change when any of the other fields are changed.
So the total field would be = quantity * price - discount.
How do you do math like this in a stimulus controller?
This is super quick and dirty, and I didn’t test it, but basically: You want to create targets for the quantity, price and total fields, so you can access them. Then, you want to create an action that’s called when the value changes. In the controller, when you connect you want to do the calculation straight away for whatever values already exist.
I was able to get it working based on your suggestions. Thanks!
One more item I am interested in. Say I dynamically add rows with items on them that all have totals. How would I then sum all of those totals together to get a master subtotal?