Save Parent record when adding to subform

Questions related to customising nuBuilder Forte with JavaScript or PHP.

Save Parent record when adding to subform

Unread postby treed » Wed Apr 14, 2021 4:00 am

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.
treed
 
Posts: 97
Joined: Mon May 18, 2020 7:32 am

Re: Save Parent record when adding to subform

Unread postby kev1n » Wed Apr 14, 2021 7:53 am

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: 2008
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: Save Parent record when adding to subform

Unread postby kev1n » Wed Apr 14, 2021 9:36 am

If you're on v4.5. try the attached and updated nudata.php which should fix the issue.
Attachments
nudata.zip
(4.89 KiB) Downloaded 37 times
kev1n
nuBuilder Team
 
Posts: 2008
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: Save Parent record when adding to subform

Unread postby treed » Thu Apr 15, 2021 5:50 am

Replaced with the new file and same results. I did reset the server and log back in.
treed
 
Posts: 97
Joined: Mon May 18, 2020 7:32 am

Re: Save Parent record when adding to subform

Unread postby kev1n » Thu Apr 15, 2021 6:02 am

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?
Attachments
sf.png
sf.png (22.38 KiB) Viewed 562 times
kev1n
nuBuilder Team
 
Posts: 2008
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: Save Parent record when adding to subform

Unread postby treed » Fri Apr 16, 2021 9:33 am

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?
treed
 
Posts: 97
Joined: Mon May 18, 2020 7:32 am

Re: Save Parent record when adding to subform

Unread postby kev1n » Fri Apr 16, 2021 2:13 pm

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
acl_1.png (8 KiB) Viewed 550 times


Then I added 1 row in a subform.

forms.png
forms.png (21.36 KiB) Viewed 550 times


As you see, both records (main + subform) were saved in the table.

db1.png
db1.png (9.43 KiB) Viewed 550 times


db2.png
db2.png (13.92 KiB) Viewed 550 times
kev1n
nuBuilder Team
 
Posts: 2008
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: Save Parent record when adding to subform

Unread postby treed » Sun Apr 18, 2021 2:45 am

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.
treed
 
Posts: 97
Joined: Mon May 18, 2020 7:32 am

Re: Save Parent record when adding to subform

Unread postby kev1n » Sun Apr 18, 2021 3:59 am

PK should be a varchar(25) and not AUTO_INCREMENT

viewtopic.php?f=19
kev1n
nuBuilder Team
 
Posts: 2008
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: Save Parent record when adding to subform

Unread postby warfreak05 » Sat Jul 10, 2021 12:03 am

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

viewtopic.php?f=19



solve my problem it works
warfreak05
 
Posts: 1
Joined: Mon Jul 05, 2021 4:08 pm
nuBuilder Version: 4.5


Return to Custom Code

Who is online

Users browsing this forum: No registered users and 4 guests

cron