Page 1 of 1

nuRunPHP in nuAddActionButton

Posted: Wed Apr 24, 2024 10:39 am
by vario
I have several "reports" that are little more than lists (i.e no grouping, subtotals etc) and I achieve a two-column layout for longer lists by an unpleasant piece of code which creates report table #TABLE_ID# with duplicate columns and then shuffles data about.

Anyway, I have been fiddling around with CSS flex & grid layouts which provide an easy way to output a list into two columns. I have a PHP procedure which generates an HTML page but if I call it from nuAddActionButton then it doesn't work. It should output a page to a new tab like it does from the onclick event of a button (or as nuRunReport does from nuAddActionButton).

Would I be right in assuming this Behaviour of the RUN button is also my answer?

Neil.

Re: nuRunPHP in nuAddActionButton

Posted: Wed Apr 24, 2024 5:31 pm
by kev1n
Hello Neil,

Are you calling nuRunReport() in nuAddActionButton() ?

Re: nuRunPHP in nuAddActionButton

Posted: Thu Apr 25, 2024 7:40 am
by vario
Yes, nuRunReport() working OK when called from nuAddActionButton(). i.e

Code: Select all

if (nuFormType() == 'browse') {
 nuAddActionButton('VehCheckRpt', 'Checklist', 'nuRunPHP("php_checklist")');
 nuAddActionButton('VehInspections', 'Inspections', 'nuRunReport("rpt_inspections")');
}
So the nuRunReport produces its PDF output in a new window, and the nuRunPHP produces no output (the button remains "down" for a moment).

Re: nuRunPHP in nuAddActionButton

Posted: Fri Apr 26, 2024 5:31 pm
by kev1n
In a test form, I added this line of code.

Code: Select all

 nuAddActionButton('VehCheckRpt', 'Checklist', 'nuRunPHP("php_checklist")');
And I created a procedure "php_checklist" with the code

Code: Select all

echo "123";
When the action button is clicked, a new tab is opened and 123 is written to the document.

Do you do anything differently? Please provide step-by-step instructions on how to replicate it.

Re: nuRunPHP in nuAddActionButton

Posted: Fri Apr 26, 2024 6:58 pm
by vario
I'm always too slow to delve into the console and debugger...

1) the console error is

Code: Select all

Uncaught TypeError: $(...).val() is undefined
2) This is from the nuBeforeSave() function which is being called:

Code: Select all

function nuBeforeSave() {
 if ($('#veh_reg').val().indexOf(" ") > 0) {
  nuMessage("No spaces allowed in registration number");
  return false;
 }
return true;
}
3) nuajax.js has this:

Code: Select all

function nuRunPHP(code, iFrame, runBeforeSave) {

	if (runBeforeSave == undefined) {
		if (window.nuBeforeSave) {
			if (nuBeforeSave() === false) { return; }
		}
	}
...
I should read the docs more often - the third parameter has fixed this. Sorry for wasting time!