Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Doing something when the last instance is of a subform is deleted

Avatar

Level 4

I have a form with a repeating subform that is first instantiated by a radio button (basically unless the "yes" button is checked the subform shouldn't display).  I have a button to add instances of the subform, and a button to delete instances of the subform, and they work fine.  However, if the last instance of the subform is deleted, I want the value of the radio button to change from "yes" to "no".  The code I've been trying is (in the "click" event)

if Description_Value_Notes_and_Office_Notes.instanceManager.count=0
          Yes_No_Base.rawValue='2';

However, not only does this not work, but it breaks my delete button.

Thanks for your help.

0 Replies

Avatar

Level 10

Is the min count of your subform set to zero?  Are you getting a message like "The element [min] has violated its allowable number of occurrences.".

You can change this in the Binding tab of the repeating subform object.

Avatar

Level 4

No, that's not the problem.  I can delete the last instance of the subform without any problem.  However, when I delete the last instance of that subform, I need to simultaneously change the value of a radio button from "yes" to "no".

Avatar

Level 10

Are you changing the value after you remove the subform or before?If after ...set the radio button first.

Paul

Avatar

Level 4

Well, that helps, but now my delete button is too enthusiastic.  To be clear, I want the radio button to change after I delete the final instance of the subform.  When I click the delete button, it will deletes more than one instance.  It's a bit inconsistent, since if I click on the delete button in the first instance of the subform (each subform has its own delete button that is supposed to delete that instance) all the instances are deleted and the radio button value is switched, but when I click on the delete button in a subsequent instance, all the instances except the first one are deleted.  Here's my script, and I'm e-mailing this to you what I have.

if (Subform_Name.instanceManager.count='1')

          Radio_Button_Group.rawValue='2'; // 2 is the value associated with the "no" button

_Subform_Name.removeInstance(this.parent.parent.index);

xfa.form.recalculate(1);

Avatar

Level 4

As usual Paul had the answer, and in my case it was a simple newbie mistake-a single equals sign assigns a value, a double equals sign compares the value.  Since I wanted to compare but was assigning, stuff messed up.  Here's the script now

if (Subform_Name.instanceManager.count=='1')

          Radio_Button_Group.rawValue='2'; // 2 is the value associated with the "no" button

_Subform_Name.removeInstance(this.parent.parent.index);

xfa.form.recalculate(1);