Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Using "Before Edit" to Populate an HTML Field

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
yvesf
Posts: 315
Joined: Sun Mar 14, 2021 8:48 am
Location: Geneva
Has thanked: 87 times
Been thanked: 11 times

Using "Before Edit" to Populate an HTML Field

Unread post 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
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

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

Unread post 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().
Post Reply