Page 1 of 1

Changing Color - Has anyone got this to work?

Posted: 2019-04-04 21:12
by kbarrett
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>";

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

Posted: 2019-04-05 06:45
by pbottcher
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>";

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

Posted: 2019-04-05 07:02
by jsetzer
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

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

Posted: 2019-04-05 19:58
by kbarrett
Hello,

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

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

Posted: 2019-04-09 19:55
by kbarrett
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?

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

Posted: 2019-04-10 06:51
by jsetzer
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

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

Posted: 2019-04-10 17:44
by kbarrett
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.

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

Posted: 2019-04-11 19:12
by kbarrett
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!