Colour a field if it has any value

Eduard B1
Tera Contributor

I'm trying to colour a field when it has any value in it. I've tried using Styles, UI Policy, Client Script but I can't get it to work. Here's what I tried in client scripts:

 

function onChange() {
var fieldName = 'caller_id'; // Replace 'caller_id' with the name of your field

var fieldValue = g_form.getValue(fieldName);

// Check the field value and apply CSS styling
if (fieldValue) {
// Apply CSS styling to change the background color when the field is not empty
g_form.addDecoration(fieldName, 'bgcolor', '#00FF00'); // Change the color to light green or any other color you prefer
} else {
// Remove any existing decoration when the field value is empty
g_form.removeDecoration(fieldName, 'bgcolor');
}
}

 

Any ideas how I can make this work?

7 REPLIES 7

dgarad
Giga Sage

Hi @Eduard B1 

You can achieve this by defining a field style on the "Color" field. Here is how you do :

 

1. Right click on the color field

 

2. go to Configure Styles.

 

3. Click on "New"

 

4. Select table where the field belongs.

 

5. Select the "Color" field in the Field name drop dow box.

 

6. In the Style field write this line: background-color:Red;

 

7. Submit.

If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad

Eduard B1
Tera Contributor

Yeah, I know how to add a colour from Styles but I don't know how to make that colour appear just when the field has a value in it

I have tried in PDI  refer below screen shot.

dgarad_0-1715176237789.png

 

dgarad_1-1715176265168.png

 

 

If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad

Eduard B1
Tera Contributor

I tried it like this but still doesn't work. I'm also working in a PDI for this. My field name is caller_id. I used javascript: current.caller_id !=""