Expand my Community achievements bar.

SOLVED

Trying to delete a specific row in Livecycle

Avatar

Level 1

Hi there. I have a form that currently has 14 rows already populated, as this form needs to be able to be printed and used with a pen in real-time as the user is making observations. The user will then take their written form back to their desk and type in their observations. With that being said, I have a "delete row" button at the end of each row. I have googled and tried every script I could find in order to delete that specific row, but nothing is working. I have done: 

 

FindingsTable.Row1.instanceManager.removeInstance(this.parent.parent.index);

FindingsTable.Row1.InstanceManager.removeInstance(this.parent.index); 

FindingsTable.Row1.removeInstance(this.parent.index); 

FindingsTable.Row1.instanceManager.removeInstance(1); 

_Row1.InstanceManager.removeInstance(this.parent.index); 

 

Then for each button's row, I would change the Row number from Row1 to Row 2, Row 3, etc. 

 

I haven't even worked on the add button yet, which I'm assuming will be much easier. 

 

Please help, thank you!!!

1 Accepted Solution

Avatar

Correct answer by
Employee
3 Replies

Avatar

Employee

To delete a specific row in  LiveCycle , you can use JavaScript code within a click event handler for the "delete row" button. Below is an example of how you can achieve this:

  1. Create a "Table" object in your LiveCycle form.
  2. Add a "Delete Row" button inside each row of the table, giving them unique names like "deleteRowBtn_1", "deleteRowBtn_2", etc.
  3. Add a click event handler for each "Delete Row" button.

Here's a sample JavaScript code to delete a specific row when the corresponding "Delete Row" button is clicked:

 

// Click event handler for the "Delete Row" buttons
function deleteRowButtonClick(event) {
  // Get the button name (e.g., "deleteRowBtn_1")
  var buttonName = event.target.name;
  
  // Extract the row number from the button name
  var rowNumber = buttonName.substring(buttonName.lastIndexOf("_") + 1);
  
  // Get the table object
  var table = xfa.resolveNode("Table1"); // Change "Table1" to the name of your table object
  
  // Get the specific row to be deleted
  var row = table.resolveNode("Row[" + rowNumber + "]");

  // Remove the row from the table
  if (row) {
    row.remove();
  }
}

// Attach the click event handler to each "Delete Row" button
xfa.host.messageBox("Form loaded");
var deleteRowButtons = xfa.resolveNodes("deleteRowBtn[*]");
for (var i = 0; i < deleteRowButtons.length; i++) {
  deleteRowButtons.item(i).addEventHandler("click", deleteRowButtonClick);
}

 

Make sure to replace "Table1" with the actual name of your table object in the code.

This code will attach a click event handler to each "Delete Row" button inside the table. When the button is clicked, the corresponding row will be identified based on the button's name, and the row will be removed from the table.

 

Avatar

Level 1

Thank you for trying to help me with this. Unfortunately, this all reads like a foreign language to me. My skills are super limited. I know how to copy and paste scripts essentially. I'm going to go google your instructions on how to "click an event handler" because I'm not sure how to do that or what it means. 

 

In the meantime, here is a screenshot of my screen, if that's helpful? 

 

Livecycle.JPG

 

Avatar

Correct answer by
Employee