Welcome to the nuBuilder Forums!

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

Save Parent record when adding to subform

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
treed
Posts: 205
Joined: Mon May 18, 2020 12:02 am
Been thanked: 2 times
Contact:

Save Parent record when adding to subform

Unread post by treed »

Hi All, When creating a new record and and then adding records to it in a subform, all the child records are lost if the parent is not saved first. What would be the best way to save the parent record before the operator enters a child record in a subform? MSAccess works this way by default.
kev1n
nuBuilder Team
Posts: 4303
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Save Parent record when adding to subform

Unread post by kev1n »

Hi,

This looks like a bug to me, I will look into it. In the meantime, add this JavaScript in the form's Custom Code field. This should fix the saving.

Code: Select all

if (nuFormType() == 'edit') {
   $('#' +nuSERVERRESPONSE.objects[0].id).addClass('nuEdited');
}
kev1n
nuBuilder Team
Posts: 4303
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Save Parent record when adding to subform

Unread post by kev1n »

If you're on v4.5. try the attached and updated nudata.php which should fix the issue.
You do not have the required permissions to view the files attached to this post.
treed
Posts: 205
Joined: Mon May 18, 2020 12:02 am
Been thanked: 2 times
Contact:

Re: Save Parent record when adding to subform

Unread post by treed »

Replaced with the new file and same results. I did reset the server and log back in.
kev1n
nuBuilder Team
Posts: 4303
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Save Parent record when adding to subform

Unread post by kev1n »

When I test it with this demo, it works just fine:

https://test.nubuilder.cloud/index.php? ... nuuserhome

Button: "Form + Subform"

Add a record, fill in the subform, save. Result: Both the records of the main form and subform are saved/created.

Do you do something different with your form?
You do not have the required permissions to view the files attached to this post.
treed
Posts: 205
Joined: Mon May 18, 2020 12:02 am
Been thanked: 2 times
Contact:

Re: Save Parent record when adding to subform

Unread post by treed »

That's certainly a similar app to what mine needs to do. I just updated the entire system from github and still behaves the same on all subforms on my system. Is the code snippet on the demo app? If not any ideas what I maybe doing wrong?
kev1n
nuBuilder Team
Posts: 4303
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Save Parent record when adding to subform

Unread post by kev1n »

treed wrote:. Is the code snippet on the demo app?
Yes, you can explore that demo.

treed wrote: If not any ideas what I maybe doing wrong?
I have no idea at the moment because I can't reproduce it and I have no idea what your form looks like, how you enter data etc...
What would really help is a Minimal, Reproducible Example.

To test it, I modified the Access Levels form to allow blanks in the main form.
acl_1.png
Then I added 1 row in a subform.
forms.png
As you see, both records (main + subform) were saved in the table.
db1.png
db2.png
You do not have the required permissions to view the files attached to this post.
treed
Posts: 205
Joined: Mon May 18, 2020 12:02 am
Been thanked: 2 times
Contact:

Re: Save Parent record when adding to subform

Unread post by treed »

Found a difference. On my order table the primary key datatype is Int(11) with an auto increment. On the example I can't tell.
kev1n
nuBuilder Team
Posts: 4303
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Save Parent record when adding to subform

Unread post by kev1n »

PK should be a varchar(25) and not AUTO_INCREMENT

https://forums.nubuilder.cloud/viewtopic.php?f=19
warfreak05
Posts: 5
Joined: Mon Jul 05, 2021 8:38 am

Re: Save Parent record when adding to subform

Unread post by warfreak05 »

kev1n wrote:PK should be a varchar(25) and not AUTO_INCREMENT

https://forums.nubuilder.cloud/viewtopic.php?f=19

solve my problem it works
Post Reply