Page 1 of 1

Save Parent record when adding to subform

Posted: Tue Apr 13, 2021 8:30 pm
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.

Re: Save Parent record when adding to subform

Posted: Wed Apr 14, 2021 12:23 am
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');
}

Re: Save Parent record when adding to subform

Posted: Wed Apr 14, 2021 2:06 am
by kev1n
If you're on v4.5. try the attached and updated nudata.php which should fix the issue.

Re: Save Parent record when adding to subform

Posted: Wed Apr 14, 2021 10:20 pm
by treed
Replaced with the new file and same results. I did reset the server and log back in.

Re: Save Parent record when adding to subform

Posted: Wed Apr 14, 2021 10:32 pm
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?

Re: Save Parent record when adding to subform

Posted: Fri Apr 16, 2021 2:03 am
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?

Re: Save Parent record when adding to subform

Posted: Fri Apr 16, 2021 6:43 am
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

Re: Save Parent record when adding to subform

Posted: Sat Apr 17, 2021 7:15 pm
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.

Re: Save Parent record when adding to subform

Posted: Sat Apr 17, 2021 8:29 pm
by kev1n
PK should be a varchar(25) and not AUTO_INCREMENT

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

Re: Save Parent record when adding to subform

Posted: Fri Jul 09, 2021 4:33 pm
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