Welcome to the nuBuilder Forums!

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

subform delete event?

Questions related to using nuBuilder Forte.
Post Reply
alf1976
Posts: 75
Joined: Tue Dec 26, 2017 8:58 pm

subform delete event?

Unread post by alf1976 »

The main record stores a variety of summarised information from the subform records.

i can keep the information updated in all circumstances apart from one: when a subform record is deleted.

There doesn't appear to be an event for this.

The only work around i can think of is to add a nuBeforeSave function and then use the nuSubformObject's deleted array as a reference to reprocess the summary data before saving.

Is this the best solution?
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: subform delete event?

Unread post by admin »

alf1976,

You can figure out a lot about what's happened in a Subform using the nuSubformObject() function in Javascript (client side) or PHP (server side).

eg. in PHP Before Save you could do this...

Code: Select all

if(array_sum(nuSubformObject('zzzzsys_browse_sf')->deleted) > 1){  //-- a record will be deleted
  //-- do something
}
Steven
alf1976
Posts: 75
Joined: Tue Dec 26, 2017 8:58 pm

Re: subform delete event?

Unread post by alf1976 »

Hi Steven,

Is to safe to add an onchange event to subform delete checkbox?

Andrew
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: subform delete event?

Unread post by admin »

alf1976,

You said...
i can keep the information updated in all circumstances apart from one: when a subform record is deleted.
Are you updating data in the browser (without saving a record) or are you updating tables on the server?

Steven
alf1976
Posts: 75
Joined: Tue Dec 26, 2017 8:58 pm

Re: subform delete event?

Unread post by alf1976 »

On the browser. If the user clicks on the delete record checkbox on the sub form I need to update the summary costs on the main record to exclude that record. As this is an estimate the correct costs needs to be displayed at all times. So I need a way to catch this event. I’m guessing I could use jquery to add a .on(“change”, handler) to each click box but I didn’t know if this would affect nuBuilder in an adverse way
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: subform delete event?

Unread post by admin »

Andrew,

I can't see a problem doing that.

You should be ok.

Steven
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: subform delete event?

Unread post by admin »

Andrew,

I have added an event called clickdelete to a subform's possible events.

You'll need the latest from Github and you'll need to run Update.

Let me know if it works for you (if you want to try it).


Steven
alf1976
Posts: 75
Joined: Tue Dec 26, 2017 8:58 pm

Re: subform delete event?

Unread post by alf1976 »

Hi Steven,

I will happily give it a try.

i got around the issue originally by adding..

Code: Select all

 $('#subformobjectName'+nuPad3(index)+'nuDelete').on( "click", 
                function(event) 
                {
                     DeleteSubRecordClick(event);
                });
to each active record when the form opens and again in the onAfterInsertRow event to catch new records.

Your new event is a far more preferable solution.
Last edited by alf1976 on Sat Apr 21, 2018 12:11 am, edited 1 time in total.
alf1976
Posts: 75
Joined: Tue Dec 26, 2017 8:58 pm

Re: subform delete event?

Unread post by alf1976 »

Hi Steven,

It works fine thank you.

Andrew
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: subform delete event?

Unread post by admin »

Thanks
Post Reply