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

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
pasbonte
Veteran Member
Posts: 162
Joined: 2013-02-06 09:49

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

Post by pasbonte » 2019-04-02 10:23

How to change the color of a field according to a condition?
Is it possible ?
Yes = green
NO = RED

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

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

Post by jsetzer » 2019-04-02 10:39

Do you mean in tableview (TV) or in detailview (DV)?
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

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

Post by jsetzer » 2019-04-02 10:50

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 1583 times
chrome_2019-04-02_12-52-42.png
chrome_2019-04-02_12-52-42.png (876 Bytes) Viewed 1583 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
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

Post Reply