Page 2 of 2

Re: nuPopup() problems

Posted: Mon Mar 05, 2018 3:14 pm
by toms
If there is no other way to retrieve the record_id, Steven might want to add an attribute like "data-nu-primary-key" to the lookup field.

Re: nuPopup() problems

Posted: Mon Mar 05, 2018 6:01 pm
by tonyd
toms-
I have been trying to reverse-engineer where to add such an attribute, but I am having some difficulty in that arena. I know the IDs I am looking for are sitting happily in the POST data, but, unfortunately, that is unreachable using javascript. If I could only figure out a way to do it using PHP. Maybe the gurus out there have a suggestion?

Re: nuPopup() problems

Posted: Tue Mar 06, 2018 1:04 am
by admin
tonyd,

If I understand you correctly...

Try this on click of your Show Button.

Code: Select all

nuPopup('theformid', $('#thelookupid').val());
Steven

Re: nuPopup() problems

Posted: Tue Mar 06, 2018 9:00 am
by toms
Steven,
tonyd wrote: Currently, the only way is to put the LookupObjectRecord_id in the 'Code' field of the object, but that just looks ugly.
In this case, $('#thelookupid').val() will cust return the code but not the record id.
toms wrote:If there is no other way to retrieve the record_id, Steven might want to add an attribute like "data-nu-primary-key" to the lookup field.
What about my suggestion?

Re: nuPopup() problems

Posted: Tue Mar 06, 2018 11:57 am
by tonyd
Tried to use a trick I googled to inject a JavaScript variable using PHP from within the index.php file:

Code: Select all

<?php
$mypostdata = json_encode($_POST);
echo "var nuPostData = $mypostdata;";
?>
Unfortunately, $_POST seems to have been nulled out before I could get the data out. Is there somewhere I can get to $_POST data before it is destroyed?

Re: nuPopup() problems

Posted: Tue Mar 06, 2018 2:47 pm
by tonyd
Got it!

Added a line to nuapi.php

Code: Select all

$f->forms[0]->target	= $P['target'];
$f->forms[0]->nuHash = $_POST['nuHash'];   (line added)
$b = nuButtons($F, $P);
which makes $_POST['nuHash'] variables available via a new window.nuSERVERRESPONSE.nuHash object.

Now I can add JavaScript to my button to open the correct edit form popup:

Code: Select all

nuPopup($('#myLookupObject')[0].dataset.nuFormId,window.nuSERVERRESPONSE.nuHash.myTableField);
This seems like a bit of a dirty hack, but it works. What do you think?

Re: nuPopup() problems

Posted: Tue Mar 06, 2018 3:54 pm
by tonyd
Well, I took out the line I had added to nuapi.php because I found out there is already a JavaScript-accessible object with the record_ids that I need.

Now I simply write a little JavaScript code for my buttons:

Code: Select all

nuPopup(window.nuSERVERRESONSE.objects[numericalObjectId].form_id, window.nuSERVERRESPONSE.objects[numericalObjectId].value);
The numericalObjectId is used to reference the particular form object in the window.nuSERVERRESPONSE.objects array, which is a zero-based identifier directly related to the object tab order on the form.

Thanks for all of the help.

Re: nuPopup() problems

Posted: Thu Mar 08, 2018 12:38 am
by admin
.