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 .
11 replies
-
Hello, I tried your above code in the console, but to my surprise, there is no result when I press the Run button. I have the macOS Ninox app.
Is there problem with console in the macOS app?
Below is my code that I tried in the script on the field:
let f := formatJSON('Order Charges'); let p := parseJSON(f); let allLineItemCharges := number(item(p, "text")); let orderTotalAmount := allLineItemCharges + 'Delivery Charges' + Adjustment; orderTotalAmount
In the end the value returned for orderTotalAmount is either "null" or zero 'cuz the textbox shows $0.00 instead of $90.00 and the balance due from the customer is -$90.00 although it should be $0.00 as the customer has already made full payment of $90.00 already.
There is another problem -- I tried to run a sample code in the console also, but nothing happens in the console. There is no output in the output window. I keep on clicking the "Run" button, but nothing happens.
-
Hello everyone, first of all thank you everyone for all your help and support in this query. This was not a very big matter if Ninox could provide the right way to do the right thing.
Using styled() for changing the background color of an element and then if this was not enough, it changes the property of the underlying value to a string.
I wish if Ninox provides a simple .backgroundColor or .bgColor property for elements, there would be no need for all this drama. Also why just format (UI/UX) formula elements, why not text boxes and number boxes
I tried the regex method also and it was super to extract numbers and currency leaving all the dust behind, however using styled starts a chain reaction between different elements (if you are using the styled values between different elements for some calculations).
I will stay with multiple callbacks to the child table as that way it is just two lines of code in every formula field and no formatting is required as no styled is used.
Alas!!
Content aside
-
4
Likes
- 4 mths agoLast active
- 11Replies
- 220Views
-
4
Following