Sub form for a subform

Questions related to using nuBuilder Forte.

Sub form for a subform

Postby sandeepgumudelli » Wed Jan 31, 2018 5:26 am

Hi,

Is it possible to create subform in a subform keeping both of them as grid?

The moment I add second subform to 1st subform nothing coming up. So tried alternative way to keep 1st subform as form and second subform as grid but no luck.

First subform work fine and the moment I add second second subform within first one it is not working as expected.

Regards,
Sandeep
sandeepgumudelli
 
Posts: 32
Joined: Fri Jan 26, 2018 12:21 am

Re: Sub form for a subform

Postby admin » Wed Jan 31, 2018 5:30 am

Sandeep,

Sorry, not in nuBuilder.

You can only go Edit > Subform eg. 1 to many.

Steven
admin
Site Admin
 
Posts: 3154
Joined: Mon Jun 15, 2009 9:53 am

Re: Sub form for a subform

Postby sandeepgumudelli » Wed Jan 31, 2018 8:56 am

Thank you for the quick response Steven.
I was thinking of alternative and included Input:Button in subform1 tried to create on click event to trigger subform2. My problem now is i couldn't find where to place click events for buttons. It was little easy in nubuilder pro but not able to find it in nubuilder forte.


Regards,
Sandeep
sandeepgumudelli
 
Posts: 32
Joined: Fri Jan 26, 2018 12:21 am

Re: Sub form for a subform

Postby admin » Wed Jan 31, 2018 10:18 am

Sandeep,

I hope this makes sense...

open_popup.PNG
open_popup.PNG (15.38 KiB) Viewed 821 times


onclick code...
Code: Select all
if(nuSubformRowId(this)==-1){alert('Must Save Record First...');}else{nuPopup('5a710cd6d4a8f5a',nuSubformRowId(this))}


'5a710cd6d4a8f5a' is the form that will be opened.

Steven
admin
Site Admin
 
Posts: 3154
Joined: Mon Jun 15, 2009 9:53 am

Re: Sub form for a subform

Postby sandeepgumudelli » Thu Feb 01, 2018 12:27 am

Thank you for the help Steven, Hugely appreciated.

With your code I am able to get the onclick working. However, I want the entry in subform to be saved as soon as I click on button for opening the popup form instead of checking if the form is saved or not. I tried the code below and a few variations of it but each time the popup-form opens and closes immediately.

Code: Select all
onclick = function(){nuUpdateData();nuPopup('5a71a4df3061331',nuSubformRowId(this));}


I also tried:
Code: Select all
onclick = function(){nuSaveAction();nuPopup('5a71a4df3061331',nuSubformRowId(this));}


Please can you give some guidance on how I can achieve saving before opening the pop-up form
sandeepgumudelli
 
Posts: 32
Joined: Fri Jan 26, 2018 12:21 am

Re: Sub form for a subform

Postby admin » Thu Feb 01, 2018 2:26 am

Sandeep,

There is no simple way to save a subform record without saving the main Edit record.

One reason is...

What happens if you click this Subform Button, and the main Edit Form has not yet been saved?

How can a Subform record be saved without knowing what the primary key of the main Edit record is, as it's needed by the Subform record as a foreign key?

How can you be born, when your father hasn't been yet.

I hate being the guy who says "That's impossible" but I can't think of a way to do it.

Steven
admin
Site Admin
 
Posts: 3154
Joined: Mon Jun 15, 2009 9:53 am

Re: Sub form for a subform

Postby sandeepgumudelli » Thu Feb 01, 2018 10:16 pm

Hi Steven,

Many thanks for your help. Actually I am not trying to save the subform ahead of main form being saved. What I am trying to do is save the mainform at the click of this button and open the subform after that.

When I try saving the form with if statement as you gave in first example just by replacing the alert with SaveAction() function, it does save the main form and second click on the button opens the subform without any issues. Problem is that if am combining the two functions for save and popup, it saves, opens the pop-up but then closes it pretty much immediately.

Do you think what I am trying to do is also not possible?

Regards,
Sandeep.
sandeepgumudelli
 
Posts: 32
Joined: Fri Jan 26, 2018 12:21 am

Re: Sub form for a subform

Postby toms » Thu Feb 01, 2018 10:50 pm

Sandeep,

I think it could be a timing issue. If you wait like 2 seconds after saving the form/before opening the pop-up, will it work?

You could try it with this code:

Code: Select all
nuSaveAction();
setTimeout(function() {
   nuAfterSave();
}, 2000);

function nuAfterSave() {
    // code to open your pop-here
}


Of course, it would be better if there was a native nuAfterSave() event so you wouldn't have to rely on a timeout.
toms
 

Re: Sub form for a subform

Postby admin » Fri Feb 02, 2018 4:22 am

Sandeep,

The best way to do what you are trying to do is this...


You could try this on the Button...
Code: Select all

if(nuSubformRowId(this)==-1){
   alert('Must Save Record First...');
}else{
   window.subform_record_id= nuSubformRowId(this);
   nuSaveAction();
}


It will Save the Edit Record and when the whole Form is reloaded the Form's Javascript is rerun so if you,

add this to the Form's Javascript...
Code: Select all
if(window.subform_record_id != ''){
   nuPopup('5a710cd6d4a8f5a',window.subform_record_id)
   window.subform_record_id = '';
}


After the Edit Form has reloaded it will bring up the Popup.

BUT THIS STILL WON'T WORK if the nuSubformRowId(this) returns -1 (hasn't been saved yet)

So its actually just a long way of doing the same thing, that won't work.



You really need to know an ID.

Another (flawed) way could be to save the row number and when the Form reloads you could try to get the id from its reloaded Subform object. eg...

http://wiki.nubuilder.net/nubuilderforte/index.php/Javascript#nuSubformObject

Code: Select all
nuSubformObject('zzzzsys_tab_sf').rows[clicked_row_number][0]


But then you have to hope nothing has been deleted or reordered - and that it's still the correct row number.


Steven
admin
Site Admin
 
Posts: 3154
Joined: Mon Jun 15, 2009 9:53 am


Return to General



cron