Page 1 of 1

How to change the color of a field according to a condition?

Posted: 2019-04-02 10:23
by pasbonte
How to change the color of a field according to a condition?
Is it possible ?
Yes = green
NO = RED

Re: How to change the color of a field according to a condition?

Posted: 2019-04-02 10:39
by jsetzer
Do you mean in tableview (TV) or in detailview (DV)?

Re: How to change the color of a field according to a condition?

Posted: 2019-04-02 10:50
by jsetzer
Tableview:
https://bigprof.com/appgini/tips-and-tu ... eview-data
https://forums.appgini.com/phpbb/viewtopic.php?t=2894

Detailview:
  1. Create a file named hooks/TABLENAME-dv.js
  2. Put the following code there:
  3. Save the file
  4. Test
Code for hooks/TABLENAME-dv.js:

Code: Select all

$j(function(){ 
    var condition = true; // replace the value by your calculated result
    var color = condition ? 'green' : 'red';
    var fieldname = "id";
    $j('#'+fieldname).css('color', color);
});
Results:
chrome_2019-04-02_12-51-15.png
chrome_2019-04-02_12-51-15.png (1005 Bytes) Viewed 2219 times
chrome_2019-04-02_12-52-42.png
chrome_2019-04-02_12-52-42.png (876 Bytes) Viewed 2219 times

Beware
If there is only little text (like in the screenshots), you will not be able to see that much difference. Additionally, 8% of all men have some kind of color-blindness, most of them have red-green-color-blindness.

Regards,
Jan