Expand my Community achievements bar.

Need assistance to my previous question

Avatar

Level 6
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.

14 Replies

Avatar

Employee Advisor

@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

Avatar

Level 6

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?

Avatar

Employee Advisor

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

Avatar

Level 6

Good day,

This is not working for me.  Please, if you can give me the full script, that would help.  I changed 

_Row1.addInstance(true);

to  

instanceManager.removeInstance(x) and it's not working.

Avatar

Employee Advisor

 for(var i=Rows;i>=-1;i--){
{
     Table1._Row1.removeInstance(i);
  }

 

assume count= Rows; Row1 is repeatable 

Avatar

Level 6

This is what I placed in the click event of the button:

 

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 (var i=Rows;i>=-1;i--){
{
Table1._Row1.removeInstance(i);
}

Avatar

Level 10

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;
	}
}

Avatar

Level 6

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.   

Avatar

Level 6

Good day,

I still need assistance to my last question as stated above....  I would like the user to be able to click on a button row and remove as many rows under that row as needed.  Right now, the script above removes the number of rows, but from the bottom of the list.  Your help is greatly appreciated.  

 

Avatar

Level 10

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;
	}
}

Avatar

Level 6

Good day,

How do I mark radzmar's latest answer as correct?