Expand my Community achievements bar.

SOLVED

Remove instance and hide subform

Avatar

Former Community Member

Hi everybody

I have an issue with the instance manager.

I have a repeated subform containing a delete button. The delete action works fine until I delete the last instance as I want the action, not only to delete the last instance, but also to hide the entire subform.

I use this script on the click event:

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

I tried to put this on the MouseUp: (found it here: http://forums.adobe.com/message/4137110#4137110)

if (this.parent.parent.instanceIndex == this.parent.parent.instanceManager.count - 1) {

           form1.Personer.presence = "hidden";

//          xfa.host.messageBox ("That was it");

}

else {

           form1.Personer.presence = "visisble";

//          xfa.host.messageBox ("Hello, still more instances");

}

If I have several instances and delete number one or two everything works fine. But if I start with deleting the last instance all previous instances are also removed and the subform “Personer” is hidden. I just wanted to remove one instance at a time.

Hope there is help out there

1 Accepted Solution

Avatar

Correct answer by
Level 10

I think what's happening is that when you are checking the Instance Manager for the count there is nothing to count because there are no instances. That and trying to do it from the object that's being removed, there's probably something there too.

To access the Instance Manager of non-existing objects you need to use the underscore shortcut.

So try this on the layout:ready event of the Personer subform:

if (_Person1.count == 0) {

     this.presence = "hidden";

}

View solution in original post

4 Replies

Avatar

Level 3

Have you tried putting parenthesis around your second condition? (this.parent.parent.instanceManager.count -1)

Or even assign it to a variable and test it that way. It looks like your if statement is always returning true, so the test is not correct. I would start with the parenthesis.

Avatar

Former Community Member

Hi GeneveX

The parenthesis didn’t change anything. So I have tried using a variable. Just a simple statement to start with, to see if I could identify the number of instances. And here seems to be a problem.

I put a statement in a button that returns a message box.

 

var nPerson1 = Personer.Person1.instanceManager.count

if (nPerson1==0)

  {

  xfa.host.messageBox("There are no instances");

  }

  else

  {

  xfa.host.messageBox("There are more instances");

  }

It works fine if there are instances, but if there are no instances I get no message box. I would expect to get a message saying “There are no instances”.

The subform is set to repeatable with no values in Min count and Max

Avatar

Correct answer by
Level 10

I think what's happening is that when you are checking the Instance Manager for the count there is nothing to count because there are no instances. That and trying to do it from the object that's being removed, there's probably something there too.

To access the Instance Manager of non-existing objects you need to use the underscore shortcut.

So try this on the layout:ready event of the Personer subform:

if (_Person1.count == 0) {

     this.presence = "hidden";

}

Avatar

Former Community Member

It seems to work.

You're wonderful Thanks a lot.