0 votes
4.0k views
in Coach Views by (270 points)
I have a scenario, where a button "Test" is added on a coachview - CV1.(This CV1 is used in many CSHS and other CVs also).

Now i want to change the colour of the button dynamically and i can achieve it by

page.ui.get("/CV1/Test").setColorStyle("DANGER");

But in another CSHS , i have CV2-->CV1--> Test button, In that case i need to change it to

page.ui.get("/CV2/CV1/Test").setColorStyle("DANGER");

is there any way to get the path dynamically using some APIs based on the controlId of the button?

1 Answer

0 votes
by (30.6k points)

A coach view knows its own control id and its parent chain through the context object, so the button inside CV1 can find out where it lives without the CSHS knowing anything about it:

// inside CV1 (the coach view that contains the button "Test"); e.g. in the button's "on click" or in CV1's load handler
var btn = me.ui.get("Test");                      // the button control object
var controlId = btn.context.viewid;               // "Test" - its control id
var fullPath = btn.context.viewid;                // same; the DOM id is btn.context.element.id (unique per repetition)
var parentId = me.context.viewid;                 // "CV1" or the id the CSHS gave this instance of CV1
var chain = []; var p = me.context.parentView ? me.context.parentView() : null;
while (p) { chain.push(p.context.viewid); p = p.context.parentView ? p.context.parentView() : null; }   // ancestors up to the coach

Two things usually behind this question:

  • Change the colour of the button - do it from CV1 with the control API instead of a CSS id (the DOM id changes per instance): btn.setColorStyle("D") (Danger), "S" Success, "P" Primary, or btn.context.element.classList.add("my-red") with a CSS file as managed asset.
  • Do it from the CSHS or another CV - address the button through the path: page.ui.get("CV1/Test") when CV1's control id is "CV1" in that coach, or page.ui.getAll ? ... : page.ui.get("Test") style lookups; for repeated CV1 instances use the index CV1[2]/Test. Pass the desired colour in as a configuration option of CV1 and let CV1 apply it in its change handler - that keeps CV1 reusable in every CSHS.

References

Related questions

0 votes
1 answer 1.9k views
0 votes
1 answer 1.7k views
0 votes
1 answer 3.1k views
0 votes
1 answer 2.4k views
0 votes
1 answer 2.1k views
0 votes
1 answer 1.4k views
0 votes
1 answer 1.2k views
0 votes
1 answer 1.3k views
0 votes
1 answer 3.1k views
0 votes
1 answer 3.2k views
0 votes
1 answer 1.6k 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
...