nuSubformArray / How to modify fields

Questions related to using nuBuilder Forte.

Re: nuSubformArray / How to modify fields

Postby toms » Sat Jan 20, 2018 8:32 am

Thanks Steven, this will help me get started.
toms
 

Re: nuSubformArray / How to modify fields

Postby admin » Sat Jan 20, 2018 4:55 pm

.
admin
Site Admin
 
Posts: 3289
Joined: Mon Jun 15, 2009 9:53 am

Re: nuSubformArray / How to modify fields

Postby alf1976 » Tue Feb 13, 2018 5:41 am

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?
alf1976
 
Posts: 75
Joined: Wed Dec 27, 2017 5:28 am

Re: nuSubformArray / How to modify fields

Postby admin » Tue Feb 13, 2018 7:07 am

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
admin
Site Admin
 
Posts: 3289
Joined: Mon Jun 15, 2009 9:53 am

Re: nuSubformArray / How to modify fields

Postby toms » Tue Feb 13, 2018 3:26 pm

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 4078 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.
toms
 

Re: nuSubformArray / How to modify fields

Postby admin » Tue Feb 13, 2018 4:53 pm

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();

}

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

Re: nuSubformArray / How to modify fields

Postby alf1976 » Wed Feb 14, 2018 4:35 am

You guys are always good for a solution. I’ll give it a go and see how I get on
alf1976
 
Posts: 75
Joined: Wed Dec 27, 2017 5:28 am

Re: nuSubformArray / How to modify fields

Postby admin » Wed Feb 14, 2018 5:23 am

.
admin
Site Admin
 
Posts: 3289
Joined: Mon Jun 15, 2009 9:53 am

Previous

Return to General