Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
Register and log in to access exclusive forums and content available only to registered users.
Add many entry to a subform
Add many entry to a subform
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 ?
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 ?
-
- 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
I created a demo here.
It's not perfect yet but it shows that it's basically possible with some custom code.
It's not perfect yet but it shows that it's basically possible with some custom code.
You do not have the required permissions to view the files attached to this post.
Re: Add many entry to a subform
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 :
Modified code :
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 :
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 ?
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);
Code: Select all
parent.nuGetLookupId(ids[i], sfName + nuPad3(i+l-1) + f, false);
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();
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 ?
-
- 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
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()
How about calling this update code also after populating the lookups?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).
Re: Add many entry to a subform
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

Thanks that is perfect

Re: Add many entry to a subform
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?
-
- 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
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);
}
Re: Add many entry to a subform
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.