Dashboard Code Mode Label Changes
Hi everyone,
I was trying to put a simple text in a dashboard which will receive a value from a JS code.
To achieve this, I've tried a few things and I had some issues that I couldn't figure out what's happening. I hope any of you guys can point me to the right direction.
Let's try to explain my approach.
If we simply pick up the reference to the field, and show it's values, we're gonna receive some interesting issues. Let's see some code:
let dataText = this.apis.canvas.select('Data');
console.log(dataText.innerText);
The above code is receiving the values from the label in a variable and I'm just showing it's innerText in console. This very values are empty even if the label has a text.
I think this happen's, because the console is showing it's values before the actual value was rendered. Every code using, is under onRenderer function, so I can't understand what's going on in this case.
To solve my issue, I created a observer, which will force this change when the value is equal to something.
let observer = new MutationObserver(function() {
if (dataText.innerText == "Test") {
dataText.innerText = "Today";
console.log(dataText);
}
});
observer.observe(dataText, { childList: true });
The above code works, but somehow, the value is not respecting the field format options, and it's rendering the result with the default values.
Is there any other way to achieve this simple change you guys can suggest or something I'm doing wrong?
Thanks in advance!
Regards,
Renato Marcello
Hi Renato,
I hope you're well.
You're right that a Mutation Observer object is the correct way to access the dataText.
I also found that changing the value of the innerText would simply re-render the object with default values. I might have to query this with the developer team to find out why and whether it's possible to keep all the original formatting. You may have to set the styling with innerHTML, e.g.
dataText.innerHTML = "<strong><span style=\"font-size: 40px;</span></strong>";
Kind regards,
Chris
Hi Renato,
I hope you're well.
You're right that a Mutation Observer object is the correct way to access the dataText.
I also found that changing the value of the innerText would simply re-render the object with default values. I might have to query this with the developer team to find out why and whether it's possible to keep all the original formatting. You may have to set the styling with innerHTML, e.g.
dataText.innerHTML = "<strong><span style=\"font-size: 40px;</span></strong>";
Kind regards,
Chris
Replies have been locked on this page!