0 votes
1.5k views
in Coach Views by (30.6k points)

1 Answer

0 votes
by (30.6k points)

Attach DOM handlers in the coach view's load event (the HTML of the view exists then) and scope every query to this.context.element so that a view used twice on a page does not grab its twin's elements:

// Coach view layout (HTML tab)
<div class="cust"><input type="text" class="cust-name"><button class="cust-go">Search</button><ul class="cust-hits"></ul></div>

// load handler
var _this = this, root = this.context.element;
var input = root.querySelector(".cust-name"), button = root.querySelector(".cust-go");
button.addEventListener("click", function () { _this.search(input.value); });
input.addEventListener("change", function (e) { _this.context.binding.set("value", e.target.value); });   // keep the binding in sync
input.addEventListener("keydown", function (e) { if (e.key === "Enter") button.click(); });
this.search = function (term) { /* call the view's Ajax service, then fill root.querySelector(".cust-hits") */ };

// unload handler (BAW 20+): nothing to do for listeners on the view's own elements - they go with the DOM;
// remove listeners you attached to window/document: window.removeEventListener("resize", _this.onResize);

Do not use inline onclick="..." attributes in the HTML: the handler would run in the global scope without access to the view. For elements created later (rows rendered by code) use event delegation on the root (root.addEventListener("click", function (e) { if (e.target.matches(".row-delete")) ... })). To fire a boundary event of the view from a DOM click, call _this.context.trigger() - the CSHS then continues its flow.

References

Related questions

0 votes
1 answer 847 views
0 votes
1 answer 1.4k views
+1 vote
1 answer 4.9k views
0 votes
1 answer 1.4k views
0 votes
1 answer 1.0k views
0 votes
1 answer 1.5k views
0 votes
1 answer 1.4k views
0 votes
1 answer 725 views
0 votes
1 answer 4.0k 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
...