Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Can't hide field in repeatable subform;only hides first instance

Avatar

Former Community Member

I have a repeatable subform which has 5 fields. I have simple code in the intialize event of the page that the subform is in to hide the 2nd field, but it only occurs in the first instance but code does not work for instances other then the first one. If the subform repeats 4-5 times the field is only hidden in the first instance. I have simple code and even used instancemanager.count & occur but doesnt work here is simple code below

Apps.Fields.DateT.presence='hidden';  //adding this in Initalize event only hides first occurance of field DateT but all other occurances field shows up

if (Apps.Fields.instanceManger.count>=1)  // Same result as previous, only hides field in first occurance
{
Apps.Fields.DateT.presence='hidden';

}

SimpleSubform_Repeat.jpgDataFilexml.jpg

7 Replies

Avatar

Level 8

In the initialize event of your subform 'Fields' put DateT.presence="hidden"

Kyle

Avatar

Former Community Member

I will be using this template for multiple fields and sometimes I will need to show the DateT field and sometimes I won't so I cannot permentaly make it hidden.

Avatar

Former Community Member

i meant ...template for multiple reports* and sometimes etc....

Avatar

Level 8

How exactly do you want it to work?

Kyle

Avatar

Former Community Member

Ok lets get a little bit more in detail:

  • The field DateT is located in a Fragment xdp which i use in many forms
  • For example lets say I have the fragment in Form1.xdp, Form2.xdp and Form3.xdp
  • In Form1 & Form2 I will show field DateT but in Form3.xdp I don't want to show the DateT field
  • Therefore, I cannot permenatly hide the field in the fragment and can only script to hide it from a field in Form1.xdp. Now lets say there is a value in the xml that comes into Form1.xdp called Case
  • For example the field 'Case' will get value either 'Son' or 'Father'
  • Conditional statement in Form1.xdp will be if "Case=='Son' then show DateT field from Fragment.xdp in all repeatable instances in Form1.xdp else if "Case=='Father' hide CaseT field in all reapeatable instances

Avatar

Level 10

Hi,

to hide all instances of an object or an objects child element you can use FormCalc with a wildcard.

if (Apps._Fields.count ge 1) then
      Apps.Fields[*].DateT.presence = "hidden"

endif

Hope this helps.

Avatar

Former Community Member

Thank you radzmar for your reply and it works perfectly when using this FormCalc script but I have to add the scrpt to an existing object that already contains Javascript code so I need a javascript version to do the samething. Luckly my co-worker helped me out and the javascript code below works:

// To get Fields node length

var nodeLength = Apps.Fields.nodes.length;
// For each rows in Fields
for (var CountInt = 0; CountInt < nodeLength; CountInt++)
{     //Hide all rows of DateT
     Apps.resolveNode("Fields(" + CountInt +  "].DateT").presence = "hidden";