Link Textcolor with Dataset

Hello everyone ,

I would like to do the following in my Lightbox:
My textfield is linked so a dataset, so it shows the state of an something. The state is maintained in a linked dataset. Now I would like to also “color-code” the state.
Like the text “full” should be shown in red and the text “free” in green.

How would I approach this with code?

Best regards.

You can try something like this:

let coloredTexts = [
{value: "full", color: "red"},
{value: "free", color: "green"},
{value: "half-full", color: "#000000"}
];
$w.onReady(() => {
$w("#dataset1").onReady(() => {
    const textValue = $w("text1").text;
    const colorObj = coloredTexts.find(e => e.value === textValue );
    if(colorObj){
        $w("text1").html = $w("text1").html.replace(">", ` style="color:${colorObj.color}">`);
    }
    })
})

The problem is that the
$w(“text1”).text; is not loading the linked dataset value,
but my placeholder text.
Somehow the code is executed before the dataset has linked and inserted the values.

Are you using $w ( “#dataset1” ). onReady () ?