Page 1 of 2

nuSubformArray / How to modify fields

PostPosted: Fri Jan 12, 2018 2:41 pm
by toms
Hi,

In nuBuilderPro I use nuSubformArray() and loop through the subform to obtain the Prefix keys in order to retrieve and set values.

How can I set values in nuBuilderForte?

Code: Select all
var subFormPrefixes = nuSubformArray('nuSubFormXYZ', false);
    for (var index in subFormPrefixes) {
        //e.g. obtaining a value:
        var ddate = $('#' + subFormPrefixes[index] + 'absdates_date').val();
       // Set a value..
          $('#' + subFormPrefixes[index] + 'absdates_hours').val("");
    }

Re: nuSubformArray / How to modify fields

PostPosted: Sat Jan 13, 2018 4:17 am
by admin
toms,

It's a lot simpler in Forte.

nuSubformObject() will give you an object that has all formatting removed (from Input:nuNumber Objects) that you can loop through.

It also has properties within it that can be used as the data for Google graphs creates with the HTML Object.
.chartData
.chartDataPivot

nuSubformObject() is both a Javascript and PHP function.

http://wiki.nubuilder.net/nubuilderforte/index.php/Javascript#nuSubformObject
http://wiki.nubuilder.net/nubuilderforte/index.php/PHP#nuSubformObject


Steven

Re: nuSubformArray / How to modify fields

PostPosted: Sat Jan 13, 2018 4:21 am
by toms
I see. Is it also possible then to modify its values and write them back.to the grid?

Re: nuSubformArray / How to modify fields

PostPosted: Sat Jan 13, 2018 4:38 am
by admin
toms,

There is no function to do that.

Steven

Re: nuSubformArray / How to modify fields

PostPosted: Sat Jan 13, 2018 6:00 am
by toms
I see. I need to figure out a way to do it. Since I need to set some default values after adding a row / multiple rows by code.

Re: nuSubformArray / How to modify fields

PostPosted: Sat Jan 13, 2018 7:34 am
by admin
toms,

You said....

I need to set some default values after adding a row


nuBuilder Forte has 2 event functions for Subform Objects, one of which you can use to prepopulate Objects in new rows afterinsertrow... http://wiki.nubuilder.net/nubuilderforte/index.php/Objects#Tab_-_Custom_Code

Steven

Re: nuSubformArray / How to modify fields

PostPosted: Sun Jan 14, 2018 7:38 pm
by toms
I'm not sure how to implement it. Adding an afterinsertrow event handler in the subform object doesn't fire the js.
Adding an afterinsertrow in the main form directly doesn't help either.

And, what are the parameters of that function. I need to get a reference to the inserted row.
Could you shed a light on this?

Re: nuSubformArray / How to modify fields

PostPosted: Mon Jan 15, 2018 2:02 am
by admin
toms,

Event is a nuScroll Object that you can scroll up and down in (giving you different events).

I think what you have done is typed it in manually and it needs to be all lowercase.

Try that.

Steven

Re: nuSubformArray / How to modify fields

PostPosted: Tue Jan 16, 2018 9:53 am
by toms
afterinsertrow fires now.

you can use to prepopulate Objects in new rows afterinsertrow...


How can I do that? After adding a new row, some default values should be set in the new row.

Re: nuSubformArray / How to modify fields

PostPosted: Tue Jan 16, 2018 9:30 pm
by admin
toms,

Add an Event, as below...

afterinsertrow2.png
afterinsertrow2.png (39.34 KiB) Viewed 57 times


And this to the Javascript of the Form...

Code: Select all

function fillNewRow(){

    var r = nuSubformObject('sf').rows.length - 1;
   
    $('#sf' + nuPad3(r) + 'field00').val('hello');
    $('#sf' + nuPad3(r) + 'field01').val('world');

}





Steven