Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Need a script to add to an "add" row button and also keep information entered in some of the columns

Avatar

Level 6

Good day,

 

Please help me to resolve this.  I cannot locate a script for what I would like to do.  I have a table that has a button to add a row and a button to remove a row.  I would like to add a button to add a row and keep whatever information that was entered in some of the columns.  Is there a script I can add to the button to accomplish this?  I cannot use the global function  of the columns because sometimes the user will need to add different information in the columns when a blank row is added.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Use the response method to ask the user, how many rows to add.

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

View solution in original post

7 Replies

Avatar

Employee Advisor

" keep whatever information that was entered in some of the columns."- Please elaborate on this, because adding a row will add a new blank row you could set the new data using instance Manager API.

Avatar

Level 6

Thank you for letting me to explain further.  I would like my form to allow the user to duplicate entries that were entered in specified columns when they add a new row with a click of a button.  Example:  Row 1, Column B has a date entered.  When the user clicks the button to add an additional row (Row 2), I want the same date in Row 1, Column B to be in Row 2, Column B. That way they will not have to enter the information manually over and over again. 

Also, on a separate question, is there a way to add a specified number of rows when your form starts with one row?  Example:  My form starts with one row, which is needed, but sometimes, my form can have hundreds of rows.  The number of rows needed is known in advance.  Can I create a button for the user to click that will allow them to enter a number and then the form will create that number of rows that they entered?   This is for Livecycle designer.

Avatar

Correct answer by
Level 10

Use the response method to ask the user, how many rows to add.

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

Avatar

Level 6

This works!  Thank you.  How would the script be if you want to remove a number of rows, just in case you add too many?

Avatar

Level 10

To copy data, use a for loop.

Given you have the following structure: Table1.Row1.Date and the Add button is located in the Row1 as well then this script will copy the date fields data to all following rows starting from the current one and where the date field is empty.

if (!Date.isNull) {
	var oRows = Table1.resolveNodes('Row1[*]'),
		j = this.parent.index,
		cDate = Date.rawValue;
	for (j; j < oRows.length; j += 1) {
		if (oRows.item(j).Date.isNull) {
			oRows.item(j).Date.rawValue = cDate;
		}
	}
}

 

 

Avatar

Level 6

Good day radzmar,

I had a follow up question to your correct answer but I'm not sure if you saw it.  Please answer my follow up question if you can......

"How would the script be if you want to remove a number of rows, just in case you add too many?"

Thank you.

Avatar

Employee Advisor

@islandgirl23 If you want to add no. of rows based on user inputs just call addInstance inside a for loop on an exit of the field which takes user inputs. This for loop will run until the user entered the value. You can call it on form initialize as well.

 

user enters X

for(var i=0;i<X;i++){

addIn

}

 

https://help.adobe.com/en_US/livecycle/10.0/DesignerScriptingRef/WS92d06802c76abadb-3e14850712a151d2...