Changing Color - Has anyone got this to work?

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
kbarrett
Veteran Member
Posts: 50
Joined: 2019-02-24 16:35
Location: Calgary Alberta

Changing Color - Has anyone got this to work?

Post by kbarrett » 2019-04-04 21:12

Hello All, using version 5.75

Has anyone got this to work? I have made several attempts and it doesn't work. And, yes I did substitute the tablename and fieldname.
$header="<%%HEADER%%><script>\$j(function(){
\$j('td.tablename-fieldname').each(function(){
if(\$j(this).text() == 'Important'){
\$j(this).parent().addClass('danger');
}
})
})</script>";

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Changing Color - Has anyone got this to work?

Post by pbottcher » 2019-04-05 06:45

Hi,

try

Code: Select all

$header="<%%HEADER%%><script>\$j(function(){
\$j('.tablename-fieldname').each(function(){
if(\$j(this).text() == 'Important'){
\$j(this).parent().addClass('danger');
}
})
})</script>";
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

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

Re: Changing Color - Has anyone got this to work?

Post by jsetzer » 2019-04-05 07:02

Did you define you own .danger class in CSS?

If not, you should do so or use bootstrap's 'text-danger' class or 'bg-danger' class instead of 'danger'.

Best,
Jan

PS: double check that .text() returns 'Important' with identical character casing and no whitespaces
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

kbarrett
Veteran Member
Posts: 50
Joined: 2019-02-24 16:35
Location: Calgary Alberta

Re: Changing Color - Has anyone got this to work?

Post by kbarrett » 2019-04-05 19:58

Hello,

Thanks to the both of you, the code that pbottcher supplied worked when I added the bootstrap class that jsetzer suggested. Thanks again.

kbarrett
Veteran Member
Posts: 50
Joined: 2019-02-24 16:35
Location: Calgary Alberta

Re: Changing Color - Has anyone got this to work? - Not working on server

Post by kbarrett » 2019-04-09 19:55

Ok,

No this is a mystery. The code suggested works perfectly as intended on my local Windows machine but when uploaded to my server it doesn't work. It's a Linux server running PHP Version 7.2.16 if that is any help. I have tried a few variations of the syntax such as upper and lower case names and well as changing the class (which shouldn't matter) but it does not work. Any thoughts?

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

Re: Changing Color - Has anyone got this to work?

Post by jsetzer » 2019-04-10 06:51

Hmmm, strange.

Can you please check the console output in you browser's developer tools to see if there is any javascript error and also check if any bootstrap-related file (css/js) could not be loaded.

If there is no error, you should ensure that your script get's executed at all for example by inserting console.log('...') in your js-code and watch the output:

Code: Select all

$header="<%%HEADER%%><script>\$j(function(){
console.log('document ready');
console.log('number of elements:');
console.log(\$j('td.tablename-fieldname').length);
\$j('td.tablename-fieldname').each(function(){
console.log(\$j(this).text());
if(\$j(this).text() == 'Important'){
console.log('equal');
\$j(this).parent().addClass('text-danger');
} else {
console.log('not equal');
}
})
})</script>";
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

kbarrett
Veteran Member
Posts: 50
Joined: 2019-02-24 16:35
Location: Calgary Alberta

Re: Changing Color - Has anyone got this to work?

Post by kbarrett » 2019-04-10 17:44

Hello,

Thanks for the console tip. I had a look one of the problems I had was a script that I had put in the footer-extras.php file to get Chrome to not cache the a javascript. I took it out, the detail view colour change works, the table view doesn't but I can live with it. I added an alert in the common.js.php file to pop up as a warning. However I did find something else interesting the following resource could not be found:
https://mywebsite/myproject/resources/l ... ox.min.map. However my Lightbox features work so I am not sure what the problem is without trying to examine a pile of code where I wouldn't know where to start.

kbarrett
Veteran Member
Posts: 50
Joined: 2019-02-24 16:35
Location: Calgary Alberta

Re: Changing Color - Has anyone got this to work?

Post by kbarrett » 2019-04-11 19:12

So to conclude this string. I added a line to the common.js.php file to create an alert when the record he or she is creating results in a the value that would prompt a colour change. As a result the record is not accepted and the user has to go back and edit the record so the value is not produced. Either way it is a win for me as the end result is what I was after anyway. Gotta love trial and error learning!

Also a big shout out to those folks on here like pboettcher and jsetzer that devote a lot of time to helping us newbies find our way.

Thanks!

Post Reply