Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Highlight content of display object

Questions related to using nuBuilder Forte.
Post Reply
JensL
Posts: 3
Joined: Thu May 07, 2020 12:45 pm

Highlight content of display object

Unread post by JensL »

Hi there,

i'm making use of a display object on a dashboard page. The display objects queries values from the database - results like "fine" or "danger".

Is there any way to highlight the text within the display object in reference to the content? Like, if the word is "danger" set color to red and font to bold?
I think the event is, when the browse form loads….

No clue how to achieve this. Thx in advance, guys

By the way: NuBuilder is a pretty cool tool, using it more and more... :D
kev1n
nuBuilder Team
Posts: 4307
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 448 times
Contact:

Re: Highlight content of display object

Unread post by kev1n »

Hi,

You can achieve that by adding some JavaScript to your form's Custom Code field.
(If you don't know how/where to do that, check out this video)

Code: Select all

if (nuFormType() !== 'browse') {
    obj = $('#replace_with_your_object_id');
    var bgColor = '';
    if (obj.val() == 'danger') {
        bgColor = 'red';
    } else
    if (obj.val() == 'fine') {
        bgColor = 'green';
    }
    if (bgColor != '') {
        obj.css('background-color', bgColor);
    }
}
You can easily add other conditions and styles, like font-weight etc: https://www.w3schools.com/cssref/pr_font_weight.asp

Also check out https://htmlcolorcodes.com/ for nicer colors.
JensL
Posts: 3
Joined: Thu May 07, 2020 12:45 pm

Re: Highlight content of display object

Unread post by JensL »

Thx for the fast replay, i will give it a try in the evening...
kev1n
nuBuilder Team
Posts: 4307
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 448 times
Contact:

Re: Highlight content of display object

Unread post by kev1n »

Here's a more elegant version that is easier to extend:

changecolor.gif

// bg: background color, fg: foreground color, weight: font feight

Code: Select all

var colorConditions = { 
    'danger':  {'bg': 'red', 'fg': 'white', 'weight': 'bold'},
    'fine':    {'bg': 'green', 'fg': 'white', 'weight': 'normal'},
    'other':   {'bg': 'black', 'fg': 'white', 'weight': 'normal'}
};

function setConditionalColors(id, conditions) {
    obj = $('#' + id);
    for (cond in conditions) {
        if (obj.val() === cond) {
            obj.css('background-color', conditions[cond]['bg']);
            obj.css('color', conditions[cond]['fg']);
            obj.css('font-weight', conditions[cond]['weight']);
            break;
        }
    }
}

setConditionalColors('objId ', colorConditions);  // replace objId with your object id
You do not have the required permissions to view the files attached to this post.
JensL
Posts: 3
Joined: Thu May 07, 2020 12:45 pm

Re: Highlight content of display object

Unread post by JensL »

Thx dude, works pretty well!
kev1n
nuBuilder Team
Posts: 4307
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 448 times
Contact:

Re: Highlight content of display object

Unread post by kev1n »

You're welcome !
Post Reply