Tinderbox Forum

Set the badge of a note dynamically

@satikusala showed how to set the badge of a note dynamically (I found no reference where… - but I know he did… so this was his idea, not mine).
I modified the code a little bit - still trying to learn TBX. So I created a small function to set the badge:

function checkBadge_db(){
	var foundNoBatch = true;
			$Badge = $BadgeTags("/gPreferences")[x];
			foundNoBatch = false;
		$Badge = "stop";

The function refers to a note to store the preferences - I call it “gPreferences” all the time and there you find an attribute called “BadgeTags”. It’s a dictionary containing a key and a value (the name of the badge to be used). Also there is a Tagger running updating an attribute NLBadge.
If you add a new line to the tagger note (tag:term 1;term 2;term 3;) you will also add this term to the BadgeTags attribute of the gPreferences note. Very easy to extend your list of badges without having to touch the function.
set_badge.tbx (112.1 KB)

Here is a link to the original thread: Attaching badge automatically when text added a note - #3 by satikusala.

I like your implementation better. My method was a kluge of conditions that does not scale very well (something I put together in 15 minutes).

The nice thing about yours in the function does not need to be touched for the inputs to work.

Now, here is an interesting question. How might we prioritize badges or signal when there is a conflict?

In this demo, if there are two matching terms, e.g. they both have Bug and See, then one (I can’t figure out which on yet, but I think it is in the order of gPreferences) will always in. If there are multiple maybe you could have a special badge for multiples, or trigger a flag. An interesting thought exercise.

The last entry in gPreference will win the race since the loop will iterate through all entries from 1 to n.
It’s easy to add the case if more then two matches were found. Add a variable var hitCount = 0; and use hitCount += 1; in the each loop. Then you can check if(hitCount>1){} to set a different badge.

I’m seeking to do something like this, but hadn’t considered a tagging approach. I thought of set up two boolean checkbox attributes for (e.g., one for “Follow up” and another “Suspicious”), so that a badge would appear when one or both of the checkboxes is checked.

I’m wondering the following…

Based on what I’m aiming to do, would it be better to use tagging or the boolean checkbox approach?

Would it be possible to have two badges (or flags) appear if both boxes or checked or are there two different graphical changes that can be applied for a note if both are checked? Or is there another, better approach when both checkboxes are checked?

As far as I understand how the code works, it would looks something like this for the the boolean checkbox approach…

$Badge=[unicode character];} else{

Is that right? Of course, I understand this changes if a note can’t have more than one badge (or flag) – and if there’s another, suggested approach (per my questions above).

Thanks for your your help!

That looks right

1 Like

Thank you. Glad I got it right!

While you’re here… Do you think it would it be better to use tagging or the boolean checkbox approach?

And is it be possible to have two badges appear if both boxes or checked?

No; a note has only one badge. A note may have several flags.