Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Button to delete all empty rows

Avatar

Level 2

I am in the process of creating an interactive form that has a button that add rows for the user to input issues and another button to add follow-ups to those instances. There are 3 different sets of these. However, we do not want to add a delete button to all rows, to allow for accidental deletion of already inputted data.  I would like to create a button that will delete all empty rows, including all subforms.  Either that, or upon saving the document, all empty rows would be deleted - whichever would be easier. Please help!  This seems like it will be a complicated task and I am not that well versed in LiveCycle to be able to figure this out on my own.

Thank you!

1 Accepted Solution

Avatar

Correct answer by
Level 10

In the Object > Binding palette. I have included a screenshot on the forum.

Niall

View solution in original post

30 Replies

Avatar

Level 10

Hi,

Here is an example that might help you: https://acrobat.com/#d=hkeDKn6SRo1FAvFUoY6Smw

The first print button lops through the repeating rows and hides the rows where the checkbox is not ticked. This option might give you some ideas.

The second print button agains loops through, but copies non-null data to another table.

Good luck,

Niall

Avatar

Level 2

Ah thank you so much for your help, but I'm still having alot of trouble with this!  I think it might be because I'm not entirely familiar with LiveCycle's language.  If I sent you the file would you by any chance mind taking a look and tell me what I'm doing wrong?!

Avatar

Level 10

It can be tricky. Can you upload your form to a file sharing site, like Acrobat.com and share the published URL here?

N.

Avatar

Level 2

I took alot of stuff out and left the basics of what I need help with (don't know if my company will like me sharing the form).

http://www.sendspace.com/file/oebzr8

It can be downloaded from there.  I also can't seem to figure out why when you add too many statements and follow-ups the title jumps to the next page.  Any way to have the title be on all pages it's child statements occur on??

Thank you so much!

Avatar

Level 2

I just realized I defined the wrong function (I deleted some stuff I tried earlier and left that) in the file I just sent, but I just fixed it to be the proper name (I think) and it still doesn't work.

Avatar

Level 10

Hi,

If you edit your post, you can delete the URL/link.

N.

Avatar

Level 10

Hi,

The script you want is:

// count the number of rows

var nCount = ObjectivesSubform.TechnicalHighlights._Row1.count;

// loop through the rows

for (var i=0; i<nCount; i++)

{

     if (xfa.resolveNode("ObjectivesSubform.TechnicalHighlights.Row1[" + i + "]").Cell2.rawValue == null)

     {

          ObjectivesSubform.TechnicalHighlights._Row1.removeInstance(i);

     }    


     // recount nCount in case a row has been deleted

     var nCount = ObjectivesSubform.TechnicalHighlights._Row1.count;

}

This loops through each instance of the repeating row and deletes it if the textfield is null.

Normally you would not need to count the number of instances INSIDE the loop, but this is necessary as rows may have been deleted.

Here is the form: https://acrobat.com/#d=XHoH91NWu*1L-YRYrS-tsQ  (I will delete it in an hour, for confidentiality).

Last point, in the add row button you have put in some additional script, which did not make sense and was causing a problem. I have commented this out.

Hope that helps,

Niall

Avatar

Level 2

Thank you so much! I don't have access to a computer right now so you don't

have to take it down. I took out all of our info.

Is the added code that you took out the reason why the title is jumping to

the next page when several instances have been added?

Avatar

Level 2

Ahh it looks like you already took it down! Would you mind putting it back

up I didn't get a chance to download. Thank you!!!

Avatar

Level 2

Oops thanks! If you add alot of rows the heading still jumps to the next

page. Is there anyway that I can specify that I want the heading to be on

both pages if the number of statements spills over?

Avatar

Level 10

Hi,

I have updated the form here: https://acrobat.com/#d=XHoH91NWu*1L-YRYrS-tsQ

There is an option if you select the Header Row, to have it repeat on every subsequent page (see Object > Pagination palette):

2010-11-12_14-37-37.png

The script in the delete button, seems to lose count because rows are being deleted. It's not too bad if there are only a few rows, but if there are a lot of rows, the delete button needs to be clicked a few times. There isn't an error showing up in the console.

Niall

Avatar

Level 2

Would maybe a loop kind of function fix that instead of a for?

Ok, I promise this is the last time I'm going to bother you - this delete

button is over my head. I figured if you did one for me I'd be able to

replicate it but it seems that the other rows are a bit more complicated

because of the way they are set up. I tried to copy your script for the

rest of the lines to the best of my ability but it's obviously not working

properly. I got the technical vital statement rows to delete, but they

would only delete if the technical highlights section had rows to delete as

well. Now I tried to add the follow-up statements in there and now it's not

working at all! AHHH this is so frustrating!

Also, when it deletes rows the ID stays at 2 and 4, etc. If you don't have

time to be bothered with this I understand but I genuinely appreciate your

help! Like I said I think I'm in over my head here!

The link for the file that I've managed to mess up again is

http://www.sendspace.com/file/5kntsx

Avatar

Level 10

I am out today, but I think the for loop working from the last row instead of the first will work better. I'll check tomorrow.

N.

Avatar

Level 2

Okay, no problem. Thanks for your time

Avatar

Level 10

Okay, I think I have it as you want the form to behave.

https://acrobat.com/#d=uO-gkfpqn5j3mRIkL1jbCQ

A couple of things:

  • For the three repeating objects I have set the initial count to "1" and unticked the min count. This works better, as the script will fail if it is trying to delete the last row.
  • I have changed the addInstance script for the three objects.
  • I have added script to the layoutReady events of the ID objects.

In relation to the delete rows, I added a line to subtract one from the count, to take into account if a row was deleted.

Hope that helps,

Niall

Avatar

Level 2

Okay, so I have literally copied and pasted the code you provided in the last form, to my full form, and the only one that it is working for is the first table.  I've literally gone line by line at least 5 times and compared the code in my form to the code in your form, and it seems to all be the same.  I have no idea what I am doing wrong and this is so frustrating!  Is there some setting that I'm missing or something???

I also would like to keep the original line in there when it deletes all the subsequent added lines if possible.  Even if it is blank.  I also need to add something that deletes the blank follow-ups but first I need to get any of it to work. 

http://www.sendspace.com/file/bdri5s

I am so sorry for being such a pain!

Avatar

Level 10

Hi,

Here is the form: https://acrobat.com/#d=E0eMdfxZU9J9NMhIjFp0Tw

The main issue is that the repeating object 'instance1' needs to be set to an initial count of '1' and un-tick minimum count. This allows all blank rows to be deleted. Otherwise the script falls over at the first table.

2010-11-15_16-34-44.png

Also watch out for naming variables that are may be reserved words, like 'h'.

Hope that helps,

Niall

Avatar

Level 2

Where do I set this so I know for next time? Not in the code right?.. is

there a drop down menu that I can't seem to find?

Avatar

Correct answer by
Level 10

In the Object > Binding palette. I have included a screenshot on the forum.

Niall