Page 1 of 1

Script help

Posted: 2022-02-07 12:40
by mfilipe
Hi Appgini community,

Need help with this script

Code: Select all

$j(function () {
	/* highlight unpaid invoices in table view */
	$j('td.cf-cf_exp_date').each(function () {
		var td = $j(this);

		var td = td.parents('tr');
		var dueDateTd = td.find('.cf-cf_exp_date');
		var dueDate = moment(dueDateTd.text(), AppGini.datetimeFormat());
		var today = moment().format('YYYY-MM-DD');
		var inProdu = document.querySelector('td.cf-cf_in_production').textContent;

		if (dueDate.isBefore(today)) {
			td.find('.cf-cf_exp_date').addClass('danger');
			td.find('.cf-cf_exp_date').addClass('text-danger');
			td.find('.cf-cf_exp_date').addClass('text-bold');
		} else if (dueDate.isSame(today)) {
			td.find('.cf-cf_exp_date').addClass('warning');
			td.find('.cf-cf_exp_date').addClass('text-warning text-bold');
		}

		if (inProdu =! null) {
			td.find('.cf-cf_in_production').addClass('success');
			td.find('.cf-cf_in_production').addClass('text-info');
			td.find('.cf-cf_in_production').addClass('text-bold');
		}

	})
})

In dueDate works fine, but take all inProdu td.cf-cf_in_production as success class.

Re: Script help

Posted: 2022-02-08 07:49
by pbottcher
Hi,

try to replace

Code: Select all

var inProdu = document.querySelector('td.cf-cf_in_production').textContent;
with

Code: Select all

var inProdu = $j('#cf-cf_in_production-'+$j(this).parent().attr('data-id')).text();

Re: Script help

Posted: 2022-02-14 10:00
by mfilipe
pböttcher,

still the same problem

Re: Script help

Posted: 2022-02-14 12:10
by pbottcher
Hi,

the text is actually not empty, so the comparison != null gives always true.

either try

Code: Select all

if (inProdu != ' ')
or try

Code: Select all

var inProdu = $j('#cf-cf_in_production-'+$j(this).parent().attr('data-id')).text().trim();
and

Code: Select all

if (inProdu !== '')
Also watch the ! (not) syntax.

Re: Script help

Posted: 2022-02-15 14:20
by mfilipe
It works!!!!

Thank you so much pböttcher!!!