Welcome to the nuBuilder Forums!

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

Add many entry to a subform

Questions related to using nuBuilder Forte.
Post Reply
damien
Posts: 30
Joined: Fri May 06, 2022 10:38 pm
Has thanked: 14 times

Add many entry to a subform

Unread post by damien »

Hello,

I have a subform that is used to manage a NxN join table.
So the subform mainly contains a lookup object.
Adding a new entry to the subform correspond to choose an element from the lookup objects.
The lookup object open the browse form to chose the element.
Every thing is ok at that point.

The only draw back is that if the user wants to add 5 rows, he must click the lookup, search elements, select in the browse.
It returns to the subform adding the element and restart 4 more times.

I wonder if there is a better solution for the user to open a kind of browse form with checkbox on each lines, select all the elements he wants, close that windows and all the selected elements will be added to the sub form.

Do you think that such behaviors is possible with nuBuilder ?
kev1n
nuBuilder Team
Posts: 4416
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 74 times
Been thanked: 472 times
Contact:

Re: Add many entry to a subform

Unread post by kev1n »

I created a demo here.

It's not perfect yet but it shows that it's basically possible with some custom code.
add_selected.png
You do not have the required permissions to view the files attached to this post.
damien
Posts: 30
Joined: Fri May 06, 2022 10:38 pm
Has thanked: 14 times

Re: Add many entry to a subform

Unread post by damien »

Waw, incredible, I will study it
Thank you very much !
damien
Posts: 30
Joined: Fri May 06, 2022 10:38 pm
Has thanked: 14 times

Re: Add many entry to a subform

Unread post by damien »

It works well, I have only modified a little bit the popuplateSubform function.
In the nuPad3 parameters I had an offset with the current number of existing lines.

Original code :

Code: Select all

        parent.nuGetLookupId(ids[i], sfName + nuPad3(i) + f, false);
Modified code :

Code: Select all

        parent.nuGetLookupId(ids[i], sfName + nuPad3(i+l-1) + f, false);
Every think works fine except a side effect on the afterinsertrow callback.
I am using the afterinsertrow of the subform object to update a display fields into the form using the lookup field values (as discussed in that thread).
I notice that with the multiple add the value of the foreign key in the lookup field is not readable or not yet present when the afterinsertrow callback is called.
In the "normal" single line add I read the lookup value using that JS code :

Code: Select all

var r = nuPad3(nuSubformObject(sfId).rows.length - 2);
var lookup_value = $('#' + sfId + nuPad3(r) + 'field_name').val();
With the multiple input the lookup_value is always a blank string.

Is it due to a fact that with that method the afterinsertrow is called before the value is updated ?
Or does the way I use to access the value is not the good one ?
What do you think about ?
kev1n
nuBuilder Team
Posts: 4416
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 74 times
Been thanked: 472 times
Contact:

Re: Add many entry to a subform

Unread post by kev1n »

damien wrote: Tue Jun 07, 2022 6:15 pm Is it due to a fact that with that method the afterinsertrow is called before the value is updated ?
I think that's the case since we're first adding new rows which triggers afterinsertrow and the lookup is only populated after calling nuGetLookupId()
I am using the afterinsertrow of the subform object to update a display fields into the form using the lookup field values (as discussed in that thread).
How about calling this update code also after populating the lookups?
damien
Posts: 30
Joined: Fri May 06, 2022 10:38 pm
Has thanked: 14 times

Re: Add many entry to a subform

Unread post by damien »

kev1n wrote: Thu Jun 09, 2022 5:46 am How about calling this update code also after populating the lookups?
Oh my good, you so right.
And cherry on the cake it is easier to update the parent field with the child data because the are already loaded into the child page !
So I just have to search it into the HTML page with jQuery, no need to go back to the SQL :P

Thanks that is perfect :thumb:
ricklincs
Posts: 107
Joined: Mon Aug 01, 2011 5:39 pm
Has thanked: 33 times

Re: Add many entry to a subform

Unread post by ricklincs »

This is a useful add many entries to a subform demo. Is it possible to add a select/deselect all button to the action buttons on top of the form so you have Select/Deselect All rows as well as the Add Selected button?
kev1n
nuBuilder Team
Posts: 4416
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 74 times
Been thanked: 472 times
Contact:

Re: Add many entry to a subform

Unread post by kev1n »

Add a new button using nuAddActionButton() to select all checkboxes:

Code: Select all


nuAddActionButton('selectAll', 'Select All', 'selectAll');

function selectAll() {
   $('input[name="mycheckbox[]"]').prop('checked', true);
}

ricklincs
Posts: 107
Joined: Mon Aug 01, 2011 5:39 pm
Has thanked: 33 times

Re: Add many entry to a subform

Unread post by ricklincs »

Thanks kev1n, works a treat.
ricklincs
Posts: 107
Joined: Mon Aug 01, 2011 5:39 pm
Has thanked: 33 times

Re: Add many entry to a subform

Unread post by ricklincs »

Kev1n is there anyway of using this code to add many enteries to a subform after you have added, saved and then edit it again to add more subform items? I added test1, test2 and test3 by using the browse_select_mulitple_lookup above and it works great. I saved the form and then edited it again to add additional items test4, test5 and test6, what it does is try to overriden the 1st 3 items(test1,test2,test3). Thanks for your help as always.
Post Reply