Set Separate Field Text Color Based on Boolean

44 views
Skip to first unread message

Randy Flinn

unread,
Sep 6, 2025, 3:56:07 PM (6 days ago) Sep 6
to mementodatabase, Vasily from Memento
In the iOS version, I have a text field that I would like to set as red or green based on the result from a Boolean field.  Is that possible?

Randy Flinn

unread,
Sep 7, 2025, 12:50:21 AM (5 days ago) Sep 7
to mementodatabase, Vasily from Memento
I am very new to JavaScript.  I was trying to create a JS field that would combine two fields into a specific format based on the quantity in one of the fields.

Essentially, if the Qty field >0, then…

Contents of field(“Item”) would join with the field(“Qty”) value.  Assume field (“Item”) = Tires and Qty = 4

Tires - (4)

If field (“Item”) = Tires and Qty = 0

Tires


if (field(“Qty”)>0,field(“Item”) + ‘ - (‘ + field(“Qty”) + ‘)’,field(“Item”))

David Gilmore

unread,
Sep 7, 2025, 11:22:00 AM (5 days ago) Sep 7
to mementodatabase
You really should create seperate threads if your questions are unrelated.

Question A:

Create a Javascript field with the following code (Assume the boolean field is named "Comnplete"):

if (field("Complete")) "#00FF00"
else "#FF0000"

You will notice the syntax of a Javascript field is a little different from other Javascript syntax.

Then set the background or foreground color (in the library settings) to that Javascript field, depending on your needs.

Bill Crews

unread,
Sep 7, 2025, 11:48:24 AM (5 days ago) Sep 7
to David Gilmore, mementodatabase
I understand neither Randy's question not James's reply. 

The direct reply would be to use...

If you just want the result Tires - 4, then...

if (field("Qty") > 0)
    field("Item") + " - " + field("Qty");

JavaScript sees that the string values indicate a string type of + and concatenates them with the stringified version of the quantity. 

 Use...

if (field("Qty") > 0) {
    field("Item") + " - " + field("Qty");

In another JavaScript field, you could have total price, if you want...

if (field"(Qty") > 0)
    field("Qty") * field("Price");



--
You received this message because you are subscribed to the Google Groups "mementodatabase" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mementodataba...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/mementodatabase/480d4454-9cfb-4eef-8a29-e85517f7e072n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages