Is it possible to apply conditional format to a text or numeric field?

203 views
Skip to first unread message

Pedro Mapo

unread,
Dec 14, 2016, 1:43:27 AM12/14/16
to mementodatabase
Is there any way to apply a conditional format?
If I have, for example a numerical field. To be able to present the result in red color if it is a negative number and in blue color  if it is positive number.
Or adjust the format of a text (color, size, bold,...) depending on the content of the text.
Would this be possible by applying some type of script to the properties of a numeric or text field? Or is there any other way to make this possible?

Bill Crews

unread,
Dec 14, 2016, 3:03:55 AM12/14/16
to mementodatabase
Generally, no, at this time in the mobile edition.

Most field types have a Font parameter that includes Color as an option.

Then, each item in a single-choice field type (Radio Buttons and Single-choice List) can have a different color in two ways -- just for a highlight or also for the display text, as well.

I thought maybe an Integer Values field could have different colors for different values, but I checked, and no, it cannot.

I'm not aware of any ability of JavaScript or Calculation field types to affect the color of the result either in the field definition or in the script.

Bill Crews

unread,
Dec 14, 2016, 4:45:53 AM12/14/16
to mementodatabase
Pedro, Eugene Kartoyev emailed me with an idea, so I implemented it, and it works! You may not like it, but let's see...

You have a field Actual containing the value you enter or calculate. You have another field Display containing nothing you ever enter or calculate.

Create an Event = Creating a new entry, Phase = Before saving the entry trigger. (On entries list screen, see 3-dot menu > Triggers. Also see http://wiki.mementodatabase.com/index.php/Triggers.) Enter (copy & paste) the following script:

message("Updating an entry: Before saving the entry"); // Remove line after it works
var e = entry(), color = '"white"';
if (e.field("Actual") < 0)
color = '"orange"';
else if (e.field("Actual") > 0)
color = '"yellow"';
e.set("Display", "<font color=" + color + ">" + e.field("Actual") + "</font>");
message("Actual = |" + e.field("Actual") + "|\nDisplay = |" + e.field("Display") + "|"); // Remove line after it works

I use a dark theme; if you use a light theme (or regardless), you might want to use different colors (maybe black for == 0, blue for > 0, red for < 0?).

After it works, remove the two lines containing the calls to message(). Now, paste the same script into another new trigger: Event = Update an existing entry, Phase = Before saving the entry.

SO... You have a separate field for displaying your value. I thought about hiding your Actual field during View and showing it on Edit (and maybe vice versa for Display), but although one can hide a field _name_, and one can make a field's visibility dependent on the value of certain field types (mostly types like Radio Buttons), I don't see a way to really do what I'd want regarding field visibility.

Now, I didn't know this about the Rich Text field type. Very little has been announced about it, and I think Eugene is the primary expert on it, besides the developer. But it implies a lot. You could make it italic, bold, underlined (not sure), bigger or smaller or with a fancy font, surround it with fancy characters, or whatever. All you need is to know a little about HTML fonts, styles, tags, etc. An area of new exploration for me. Thanks, Eugene!

Bill Crews

unread,
Dec 14, 2016, 4:51:35 AM12/14/16
to mementodatabase
Woops! I forgot to say that Actual could be an Integer field, or any other number field type or a JavaScript field that returns a number value or a Calculation field with result type Integer or Real, and Display should be a Rich Text field.

Pedro Mapo

unread,
Dec 15, 2016, 1:45:12 PM12/15/16
to mementodatabase
It doesn´t look very nice..., but it certainly works. Thanks for the help.

Eugene Kartoyev

unread,
Dec 15, 2016, 2:33:32 PM12/15/16
to mementodatabase
Oh, Pedro! If you apply some html styling to the rich text field it can look veeeery nice! Believe me!

Actually, Bill and I were discussing rtf fields the other day, thinking it was kind of almost useless with no integration to pdf.

We knew it's content was based on html, so what! We didn't know what to do with that.

Now, with your question a new idea just good for rtf fields popped up - one can use it to fill with html content generated from text in other fields.

So, now if someone asks if you can make formatted reports within a cardview - the answer will be yes! All kind of reports.

Whatever you see on an internet page, you can get into rtf field, like pictures, tables, texts, fancy fonts, styles...

It's very powerful, in fact.

Eugene Kartoyev

unread,
Dec 15, 2016, 2:46:56 PM12/15/16
to mementodatabase
Bill, on the other hand, why use sidepaths to fill in the rtf field?

As Vasya's spokesman, you simply must force him to add a webview field with all possible permissions set, like scaling and javascript enabled, so people can make custom fields, even with videos or music by injecting scripts openly offered by such sites as youtube.

I think that would make everyone (and me, in particular) come to the complete bliss!

Bill Crews

unread,
Dec 15, 2016, 3:13:36 PM12/15/16
to mementodatabase
So, now I'm Vasya's spokesman?! I think not! I'm an enthusiastic user and can write wiki pages.

I could be wrong, but I interpreted Pedro's statement that it wasn't pretty to mean that you have to have the Actual field over here and the Display field over there, and you can't hide the Display field on the edit card, and you can't hide the Actual field on the view card, and so on. I don't think he's saying the Display field just isn't pretty enough.

You know, I think you can write to sup...@MementoDatabase.com the same as I can, and you can make your case just as well. Of course, you can also put stuff in UserVoice. I'll be there to advocate for it when the time is right. I'm NOT on the inside.

Pedro Mapo

unread,
Dec 16, 2016, 2:05:09 AM12/16/16
to mementodatabase
Bill is right. 
I meant that it´s visually a little messy that you have to have the Actual field over here and the Display field over there, and you can't hide the Display field on the edit card, and you can't hide the Actual field on the view card, and so on, as Bill said.

Eugene Kartoyev

unread,
Dec 17, 2016, 2:08:39 AM12/17/16
to mementodatabase
One can use dependencies as Bill said. However, I often need to to have a quick look at this "backyard" calculation data to analyse if something seems out of order. So, I prefer to maintain a separate Settings tab for all the data that is not needed to be seen in a nourmal course of work, like in the attached screenshot.
1481958463933-466634512.jpg

Bill Crews

unread,
Dec 17, 2016, 7:29:50 AM12/17/16
to mementodatabase
Ah! Yes, good idea, Eugene. If you keep Display on the MAIN tab and have a separate tab (Add Page, in the Plus button in the lower-right corner of the Library Edit screen) for Actual and other such things, that would ALMOST be clean & pretty. You'd just have to hit the tab (or swipe to the right in the entry edit card) to edit Actual. Not bad.

Pedro Mapo

unread,
Dec 20, 2016, 10:06:17 AM12/20/16
to mementodatabase
I send some screenshots with my solution and a template.
Thanks for your great help.
01.jpg
02.jpg
03.jpg
04.jpg
05.jpg
06.jpg
07.jpg
08.jpg
Conditional color amount Memento_v4.1.0.template
Reply all
Reply to author
Forward
0 new messages