Expand my Community achievements bar.

insertInstance() not working

Avatar

Former Community Member
I have a form which can add continuation pages to several fields. I initially have all of the continuation pages presence set as "hidden" with a button/check box to add another page using insertInstance(). For some reason insertInstance() is not working. It does work fine if the pages are initially "visible". Any ideas as to why this wouldn't work? Here is the code I'm using:



var i = Page20.instanceIndex + 1;

Page20.instanceManager.insertInstance(i, 0);
2 Replies

Avatar

Former Community Member
If the subform is hidden then it does not really exist in the layout and any reference to that object cannot be resolved. If there is at least one instance of the object then your syntax will work (like when you make it visible). There was a syntax created to communicate with the instance manager to allow you to add an instance when a base object does not exist yet. To do this use the syntax below:



_Page20.insertInsatnce(i,0);



The underscore (_) indiicates that you are communicating with the named subforms instance manager.

Avatar

Former Community Member
Thanks Paul, that helped.

I think also when you create an instance of a subform that was originally "hidden" from the layout the new instance starts out that way.

I was able to work around that by converting i to a string, creating a variable set as Concat("Page20[", i, "]"), and then setting the presence of that to "visible".



Thanks again,

Ian Hockett