0 votes
1.3k views
by (21.5k points)

1 Answer

0 votes
by (30.6k points)

Every UI Toolkit control has events (On click, On change, On row selected, On load, ...) whose value is JavaScript that the framework runs with the control as me. To connect a function of your own coach view, expose the function on the view and call it from the event text with control addressing:

// 1. In your coach view "OrderTools" (the parent that contains the toolkit controls), load handler:
var _this = this;
this.recalc = function (source) {
  var lines = _this.ui.get("Lines").getData() || [];
  var total = lines.reduce(function (s, l) { return s + (l.qty || 0) * (l.price || 0); }, 0);
  _this.ui.get("Total").setData(total);
  if (source) console.log("recalc triggered by", source.context.viewid);
};

// 2. In the toolkit control's event (e.g. Decimal "Price" inside the table > On change):
//    address the parent view and call its function; "me" is the control that fired
me.ui.getParent ? me.ui.getParent().recalc(me) : page.ui.get("OrderTools").recalc(me);
// shorter when the parent id is known:   ${OrderTools}.recalc(me)

Three details: (a) functions must be attached to the view object (this.recalc = ...), not declared with function recalc() - the latter is invisible outside the handler; (b) inside a repeating table the control's path includes the row, so use relative addressing (me.ui.get("../../Total")) or the parent lookup; (c) for the reverse direction - a coach view listening to a control - keep the wiring in the control's event text as shown, or attach a DOM listener to the control's element (${Price}.context.element.addEventListener("change", ...)).

References

Related questions

0 votes
1 answer 793 views
0 votes
1 answer 1.2k views
0 votes
1 answer 1.3k views
0 votes
1 answer 722 views
0 votes
1 answer 1.1k views
0 votes
1 answer 2.5k views
0 votes
1 answer 899 views
0 votes
1 answer 1.7k views
0 votes
1 answer 852 views
0 votes
1 answer 4.0k views
0 votes
1 answer 1.4k views
0 votes
1 answer 1.0k views
0 votes
1 answer 1.9k views
0 votes
1 answer 2.1k views

723 questions

807 answers

98 comments

4.9k users

Join BPM Community Discord Channel

Welcome to BPM Tips Q&A, Community wiki/forum where you can ask questions and receive answers from other IBM BPM experts and members of the community. Users with 2000 points will automatically be promoted to expert level.
Created by Dosvak LLC
Our Youtube Channel
...