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.

Nesting "If" Statements

Avatar

Former Community Member

I'm trying to use a radio button to control a repeating subform and the subform containing it.  When the value for the radio button is "no", the containing subform is hidden, but the repeating subform contained within it isn't altered (so in case someone makes a mistake they don't lose all of their data).  When the radio button value is "yes", the containing subform is rendered visible, and I'd like to have it add an instance of the repeating subform only if there are no instances of it currently.  Unfortunately, I can't get the second part to work, and for various reasons I can't use the Initial Count or Minimum Count properties in the Bindings tab.  Here's the code I'm using (in the "change" event of the radio button group):

if (this.rawValue=='1'){

          Container_Subform.presence="visible";

          if (Container_Subform.Repeating_Subform.instanceManager.count=='0')

               Container_Subform._Repeating_Subform.addInstance(1);

               xfa.form.recalculate(1);

}

I'm thinking it must be something simple, but I can't think of it.  Thanks in advance for your help.

5 Replies

Avatar

Level 10

Hi,

I can't test this at the moment, but your if statements could be contained within {}

if (this.rawValue == 1)

{

     Container_Subform.presence="visible";

     if (Container_Subform.Repeating_Subform.instanceManager.count == 0)

     {

          Container_Subform._Repeating_Subform.addInstance(1);

          xfa.form.recalculate(1);

     }

}

Someone else will probably have more robust advice.

Good luck,

Niall

Avatar

Former Community Member

Unfortunately, that didn't work.  Any other ideas?

Avatar

Former Community Member

I figured out how to do what I was trying to do.  It doesn't involve nested "If" statements, but it works.

form1.#subform[0].Name.Radio_Button_Group::change - (JavaScript, client)

if (this.rawValue=='1') && (Container_Subform._Repeating_Subform.count < '1'))

          Container_Subform._Repeating_Subform.addInstance(1);

          xfa.form.recalculate(1);

form1.#subform[0].Name.Radio_Button_Group.Yes::change - (JavaScript, client)

Container_Subform.presence="visible";

form1.#subform[0].Name.Radio_Button_Group.No::change - (JavaScript, client)

Repeater_Subform.presence="hidden";

Avatar

Level 2

I'm trying to do something similiar is it possible you can post a sample of your form?

Thank you.

Avatar

Former Community Member

I actually ended up doing things differently, and I don't think I have a working example.  It's not too hard though, just take your radio button group, insert the code above (be sure you're using JavaScript) into the Script Editor in the "change" event (make sure you have the "visible" and "invisible" under the "Yes" and "No" sections), change the names so they match your form, then make sure your repeating subform is set to "Repeat Subform for Each Data Item" under the Bindings tab in the Object palette, then make sure you have the repeating subform and all of the subforms containing it set to "Flowed".  That ought to do it.