Page 1 of 1

Using "Before Edit" to Populate an HTML Field

Posted: Fri Apr 11, 2025 5:28 am
by yvesf
Hi,

Hi,

I would like to use the Before Edit (BE) event in PHP and understand how it works. It is in the browse and edit form patients section.

My goal is to populate an html field (used like a display field) that supports carriage returns.
I’ve created an HTML object named

Code: Select all

htmlResumePatient
, and I’d like to populate it via the Before Edit event using the following code:

Code: Select all

$pat_id = '#RECORD_ID#';

$sql = "SELECT CONCAT(
    p.pat_civilite, ' <b>',
    p.pat_prenom, ' ',
    p.pat_nom, '</b>, <b>',
    TIMESTAMPDIFF(YEAR, p.pat_date_naissance, CURDATE()), ' ans</b>, né ',
    p.pat_ald
) AS resume
FROM patients p
WHERE p.pat_id = '$pat_id'";

$res = nuRunQuery($sql);
$row = db_fetch_array($res);
$texte = addslashes($row['resume']);

nuJavaScriptCallback("nuSetValue('htmlResumePatient',`$texte`,'html');");
However, this doesn’t seem to work.
I also tried the simpler version:

Code: Select all

nuJavaScriptCallback("nuSetValue('htmlResumePatient',`test`,'html');");
…but I still get no result.

Could you confirm whether nuJavaScriptCallback() is actually executed in the Before Edit context? Or am I missing something (maybe just a typo I can’t spot after a long night…)?

Also, more generally:
What kind of code is best suited for the "Before Edit" event?
I’ve noticed that the echo() function often crashes the solution in nuBuilder — as is usually the case when using it.
What are the limitations in terms of updating or displaying content?

Thanks a lot in advance for your help!

Best regards,
Yves

Re: Using "Before Edit" to Populate an HTML Field

Posted: Fri Apr 11, 2025 6:50 am
by kev1n
You almost got it right but use nuAddJavaScript() in BE and
nuJavaScriptCallback() when executing a procedure via nuRunPHP() or nuRunPHPHidden().

Avoid using echo(), var_dump(), and similar functions in BE, BS etc. — use them only within nuRunPHP().