Page 1 of 1

Sub form for a subform

Posted: Tue Jan 30, 2018 8:56 pm
by sandeepgumudelli
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

Re: Sub form for a subform

Posted: Tue Jan 30, 2018 9:00 pm
by admin
Sandeep,

Sorry, not in nuBuilder.

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

Steven

Re: Sub form for a subform

Posted: Wed Jan 31, 2018 12:26 am
by sandeepgumudelli
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

Re: Sub form for a subform

Posted: Wed Jan 31, 2018 1:48 am
by admin
Sandeep,

I hope this makes sense...
open_popup.PNG
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

Re: Sub form for a subform

Posted: Wed Jan 31, 2018 3:57 pm
by sandeepgumudelli
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

Re: Sub form for a subform

Posted: Wed Jan 31, 2018 5:56 pm
by admin
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

Re: Sub form for a subform

Posted: Thu Feb 01, 2018 1:46 pm
by sandeepgumudelli
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.

Re: Sub form for a subform

Posted: Thu Feb 01, 2018 2:20 pm
by toms
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.

Re: Sub form for a subform

Posted: Thu Feb 01, 2018 7:52 pm
by admin
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/nubuilderfort ... formObject

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