Page 2 of 2

Re: nuSubformArray / How to modify fields

PostPosted: Sat Jan 20, 2018 8:32 am
by toms
Thanks Steven, this will help me get started.

Re: nuSubformArray / How to modify fields

PostPosted: Sat Jan 20, 2018 4:55 pm
by admin
.

Re: nuSubformArray / How to modify fields

PostPosted: Tue Feb 13, 2018 5:41 am
by alf1976
To extend Toms query

i need the ability to update subforms based upon the main form

My main form contains the quantities for the estimate. If they change i need the ability to go into each subform and update various calcuations to recalcuate costs

The calcuations are not straight forward, so if on a main form i would have functions to process these and update other fields. On a subform the Javascript is grey out.

i could get around this by having the calculation functions on the main form. An onchange from a subform object does fire on the main form, but this isnt much help as as i cannot see any way of
knowing which record actually sent it (and even if i did there isnt a function to manipulate subform data)

Is this something that can be looked at in the future?

Re: nuSubformArray / How to modify fields

PostPosted: Tue Feb 13, 2018 7:07 am
by admin
Andrew,

You can do whatever you like already.

You don't have to use Calc Objects to add stuff up.

If you have something complex, use a readonly, Input:nuNumber Object and set its value to whatever you want with Javascript.

Steven

Re: nuSubformArray / How to modify fields

PostPosted: Tue Feb 13, 2018 3:26 pm
by toms
alf1976 wrote: An onchange from a subform object does fire on the main form, but this isnt much help as as i cannot see any way of
knowing which record actually sent it


Add an onchange event handler to your subform objects and pass the event parameter to retrieve the sender-control from the passed event parameter.

onchangehandler.PNG
onchangehandler.PNG (4.63 KiB) Viewed 4172 times


In you main form, add this js event handler:

Code: Select all
function myOnChangeHandler(event) {
//   console.log(event.target);
// add the code from below
}



alf1976 wrote: (and even if i did there isnt a function to manipulate subform data)


Then you can retrieve information about the target object (name, subform, row number) and change other fields that are on the same row.

e.g. (untested!)

Code: Select all
var t   = $('#' + event.target.id)[0];
var p   = $('#' + t.id).attr('data-nu-prefix'); // field that triggered the event
var s           = event.target.attr('data-nu-form'); // subform
var n          = p.substr(p.length - 3); // extract the row number

var field = 'myotherfield';
$('#' + subform + nuPad3(n) + field).val('hello!').change();


I hope that helps.

Re: nuSubformArray / How to modify fields

PostPosted: Tue Feb 13, 2018 4:53 pm
by admin
Andrew,

If we are understanding your question correctly...

Code: Select all

function myOnChangeHandler(e) {

   var p   = $('#' + e.target.id).attr('data-nu-prefix');
   var f   = "myotherfield";

   $('#' + p + f).val('hello!').change();

}


Re: nuSubformArray / How to modify fields

PostPosted: Wed Feb 14, 2018 4:35 am
by alf1976
You guys are always good for a solution. I’ll give it a go and see how I get on

Re: nuSubformArray / How to modify fields

PostPosted: Wed Feb 14, 2018 5:23 am
by admin
.