Need assistance to my previous question | Community
Skip to main content
Level 5
May 30, 2022

Need assistance to my previous question

  • May 30, 2022
  • 2 replies
  • 2406 views
var cInput = xfa.host.response("Enter number of rows you want to add:", "Add rows", "1", false),
	n = parseInt(cInput, 10) > 0 ? parseInt(cInput, 10) : 1,
	i = 0;
for (i; i < n; i += 1) {
	_Row1.addInstance(true);
}

Good day,  I posted a question about adding rows to a table and the above script from Radzmar was the solution.  I posted a follow up question to my answer and have not received a reply so far, so I'm reposting it here just in case it was overlooked.  

Is there a script to remove rows the same way?  In case the user adds too many rows, I do not want them to have to remove the rows one at a time.  Your assistance is appreciated.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

2 replies

Mayank_Gandhi
Adobe Employee
Adobe Employee
May 30, 2022

@islandgirl23 For that you need to be aware of count and run the for loop and fire 

instanceManager.removeInstance(x)

 Where x is the index.

Count>=x

Level 5
May 31, 2022

Good day,

I would like the same function as the script above.  It will need to ask the user how many rows to delete and then remove them.  So, where would I place "instanceManager.removeInstance(x)" in the script above?

Mayank_Gandhi
Adobe Employee
Adobe Employee
June 1, 2022

@islandgirl23 In place of addinstance code only, make sure the value by the user doesn't exceed the current total count of instances. 

radzmar
Level 10
June 10, 2022

Hi,

 

this should do the trick: 

if (_Row1.count > 1) {
var nRows = _Row1.count,
	cInput = xfa.host.response("How many of the current " + nRows + " do you want to remove?", "Remove rows", "1", false),
	n = parseInt(cInput, 10) > nRows ? nRows - 1 : parseInt(cInput, 10),
	i = 0;
	
	while (n > 0) {
		_Row1.removeInstance(_Row1.count -1);
		n -= 1;
	}
}
Level 5
June 11, 2022

Good day, Thank you for responding.  This is almost what I'm looking for.  It works, but partially. This works properly only if I click the button attached to the first row.  My form have buttons on each row and it doesn't work properly if I click on any of the other buttons .  I would like the user to click on a button row and remove as many rows under that row as needed. Also, my form have item numbers in one of the blocks of the row.  Any numbers entered in that block of the remaining rows cannot change when the rows are deleted.  Right now they do.   

Level 5
June 25, 2022

I guess this script work as you want. However I didn't fully test it.

 

if (_Row1.count > 1) {
var nRows = _Row1.count,
	nIndex = this.parent.index, // Get index of current table row, outgoing from the button. The SOMexpression might be different in your form! This one works for a button put directly into a cell of Row1.
	cInput = xfa.host.response("How many of the current " + nRows + " do you want to remove?", "Remove rows", "1", false),
	n = parseInt(cInput, 10) > nRows ? nRows - 1 : parseInt(cInput, 10);

	while (n > 0) {
		console.println("nRows: " + nRows + " - nIndex: " + nIndex + " n:" + n)	
		_Row1.removeInstance(nIndex + 1);
		n -= 1;
	}
}

Thank you!  This works perfectly.