Page 1 of 1

subform delete event?

Posted: Wed Apr 11, 2018 12:22 am
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?

Re: subform delete event?

Posted: Wed Apr 11, 2018 3:34 am
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

Re: subform delete event?

Posted: Thu Apr 12, 2018 8:56 pm
by alf1976
Hi Steven,

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

Andrew

Re: subform delete event?

Posted: Fri Apr 13, 2018 1:07 am
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

Re: subform delete event?

Posted: Fri Apr 13, 2018 12:48 pm
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

Re: subform delete event?

Posted: Fri Apr 13, 2018 9:07 pm
by admin
Andrew,

I can't see a problem doing that.

You should be ok.

Steven

Re: subform delete event?

Posted: Fri Apr 20, 2018 12:58 am
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

Re: subform delete event?

Posted: Fri Apr 20, 2018 11:29 pm
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.

Re: subform delete event?

Posted: Sat Apr 21, 2018 12:01 am
by alf1976
Hi Steven,

It works fine thank you.

Andrew

Re: subform delete event?

Posted: Sat Apr 21, 2018 5:08 am
by admin
Thanks