Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.

Instance of Presence Property

Avatar

Former Community Member
I'm trying to hide a Delete Button until a subform is added, then I want the Delete Button to show on all instances. I've put a presence = "invisible" script in the docReady of the Button and that works. The problem I'm having is that if the user add instances of the subform and saves it, when they reopen the form all the Delete Buttons go away because of my docReady script. How can I get to a specific instance of the Presence Property? I'm trying to write a script that would only make the 0 index of the Delete Button invisible, but I can't seem to use an index with this property.

Thanks,

Ken
4 Replies

Avatar

Former Community Member
Hi :-)

I think that you can fix whit a script like below (JavaScript):



var app_index = parseInt(parent.detail.all.length)-1;

xfa.resolveNode("parent.detail[" + app_index +"].txt_estesa").rawValue



"detail" is the subform that I use to add instances of some fields and "txt_estesa" is one of theee.

With this script I get the last instance of my subforms.



For every instance of the subform "detail" I have a button to delete it and this is the script in the click event:



// Invoke the Instance Manager to remove the current instance of the detail subform.

_detail.removeInstance(this.parent.index);



// Invoke the recalculate method to update the form calculations.

xfa.form.recalculate(1);



I hope that this helps :-)

Bye,

Roberto.

Avatar

Former Community Member
Thanks for the info, but I'm trying to find out how to use the presence property for a specific instance. I can add and remove subforms fine. I want to be able to look at how many instances of a subform there is on open and if there is only 1 do not display the delete button, but if there is more than one I want to display the delete button. Sorry if this sounds confusing. I'm having a hard time explaining it.



Ken

Avatar

Former Community Member
Hi,



If you want to display the delete button only if subform have more than one line, here is the code:



var oNodes = xfa.resolveNodes("form1.subform.line[*].field") //any field of the line

var nNodesLength = oNodes.length;

if (this.parent.index == 0 & nNodesLength == '1'){

deletebutton.presence = "hidden"

xfa.form.recalculate(1);

}