Welcome to the nuBuilder Forums!

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

PHP after browse in select object Topic is solved

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

Re: PHP after browse in select object

Unread post by yvesf »

DET_TYPE_ID is an object. I have tried in smaller case.
Here is a screenshot of this object id
CCSelect.PNG
and the related procedure in which I should retrieve the value of det_type_id object.
procRecup.PNG
And the result in nuDebug
nuDeBUG.PNG
I don't see a solution :cry:
Many thx,

Yves
You do not have the required permissions to view the files attached to this post.
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: PHP after browse in select object

Unread post by kev1n »

Can you show a screenshot of the table schema?
yvesf
Posts: 315
Joined: Sun Mar 14, 2021 8:48 am
Location: Geneva
Has thanked: 87 times
Been thanked: 11 times

Re: PHP after browse in select object

Unread post by yvesf »

Here is the schema.
Detail is a subform of Acte browse and edit form
Type is a browse and edit form
Schema.PNG
Many thanks,

Yves
You do not have the required permissions to view the files attached to this post.
yvesf
Posts: 315
Joined: Sun Mar 14, 2021 8:48 am
Location: Geneva
Has thanked: 87 times
Been thanked: 11 times

Re: PHP after browse in select object

Unread post by yvesf »

Here is a backup of the database :
07-15-2023_151920_64b2c70872c87_nuBuilder_backup.sql.gzip
You do not have the required permissions to view the files attached to this post.
yvesf
Posts: 315
Joined: Sun Mar 14, 2021 8:48 am
Location: Geneva
Has thanked: 87 times
Been thanked: 11 times

Re: PHP after browse in select object

Unread post by yvesf »

If we are not in a subform, your solution works without any pb.
-->
Video_2023-07-16_004454.gif
with behind the custom code of the act_activities object

Code: Select all

nuRunPHPHidden('Montant');
and procedure Montant as following :

Code: Select all

$s  = "SELECT aty_montant FROM activity WHERE aty_code = ?";
$t  = nuRunQuery($s, array('#act_activities#'));

if (db_num_rows($t) == 1) {
    $r  = db_fetch_object($t);


   $js= "nuSetValue('act_montant', $r->aty_montant);";
nuJavaScriptCallback($js);
}
But if we are in a subform, it doesn't work unfortunately.
If you could help.

Yves
You do not have the required permissions to view the files attached to this post.
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: PHP after browse in select object

Unread post by kev1n »

In the subform, each object in a row has a unique ID. You can first set a hash cookie containing the value of the select object. Then, proceed to call the 'nuRunPHPHidden()' function.

Code: Select all

nuSetProperty('det_type_id', this.value);
nuRunPHPHidden('RecupMontant', 0);
yvesf
Posts: 315
Joined: Sun Mar 14, 2021 8:48 am
Location: Geneva
Has thanked: 87 times
Been thanked: 11 times

Re: PHP after browse in select object

Unread post by yvesf »

Great thanks, with this approach, I can effectively pass the value to the subform. But in the procedure, how can I know the unique ID of the object corresponding to det_montant ? I have also to pass this value to the procedure at the same time as you set the det_type_id hash cookie.
How can I do that ?
In Custom code

Code: Select all

nuSetProperty('det_type_id', this.value);
nuSetProperty('det_montant', nuGetValue('det_montant'));
nuRunPHPHidden('RecupMontant', 0);
In the related procedure RecupMontant

Code: Select all

$s  = "SELECT type.typ_montant FROM type where type.typ_code = '#det_type_id#'";
$t  = nuRunQuery($s, array('#det_type_id#'));

if (db_num_rows($t) == 1) {
   $r  = db_fetch_object($t);

$js="nuSetProperty('det_montant',$r->typ_montant);";
  nuJavaScriptCallback($js);
   
}
The assignment doesn't work even if I put nuSetValue instead of nuSetProperty. Many thanks for your help.

Yves
Last edited by yvesf on Sun Jul 16, 2023 9:28 am, edited 1 time in total.
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: PHP after browse in select object

Unread post by kev1n »

Also pass the ID of det_montant to php by setting an hash cookie in JS:

Code: Select all

const montantId = nuSubformRowObject(this.id, 'det_montant').attr('id');
nuSetProperty('montantId', montantId);
In PHP, retrieve it like this:

Code: Select all

 $js= "nuSetValue('#montantId#', $r->aty_montant);";
yvesf
Posts: 315
Joined: Sun Mar 14, 2021 8:48 am
Location: Geneva
Has thanked: 87 times
Been thanked: 11 times

Re: PHP after browse in select object

Unread post by yvesf »

Great thanks Kev1n !!! :lol: It effectively works as expected. What a such work to do that in subform !!! But it works perfectly.

Yves
Post Reply