Extract color or icon from styled field/var
I needed to extract the icon and colour from a styled value. The color() and icon() functions work for the choice field, but not for styled.
When I looked up how to do this, I saw that styled is a JSON structure. If you write this code in the Ninox console :
var s := styled( "hello", "yellow", "blue", "rainbow");
debugValueInfo(s);
it returns: styled({"text": "hello", "color": "blue", "background": "yellow", "icon": "rainbow"})
So, if you use the item() function, you can extract all the values:
item(Styled, "color")
return : blue
but the returned value type is always styled: debugValueInfo(item(s, "color")) ; return styled("blue")
To retrieve a textual value, use the string() function because the text() function will use a formatting function that will always return the text of a styled variable. string() function return a text representation of the value as it is:
var s := styled( "hello", "yellow", "#125", "rainbow");
string(item(s, "color"));
return : blue
The debugger can help you see the type and content of variables.
I'm not sure if this tip is useful to anyone, but you never know .
Reply
Content aside
-
4
Likes
- 1 yr agoLast active
- 104Views
-
1
Following