Script Dependencies and "recalculate()"
I follow the example here, and use it to do the dynamic form. The +/- button now work as my Add/Delete row button.
And I find a problem:
the table is created and rows are repeating. I make the row min=1, initial count =4, no max.
But when you click on "Add row"/"Delete row" button, it's adding/deleting the instance of the first row always. I want to modify the last row instead.
my script (most alike the samples):
Add row:
function addRow(addButton){
/*
This button will insert one instance of the repeating subform or table row.
message: The error message displayed.
*/
var message = "You have reached the maximum number of items allowed.";
// DO NOT MODIFY THE CODE BEYOND THIS POINT - 8.2.1.3158.1.475346.466429 - Subform_Instance_Controls_IRM.xfo.p2
var oTargetSubform = addButton.parent.repeatingTable.repeatingRow; // The subform or table row the controls are intended to manipulate.
var oManager = oTargetSubform.instanceManager; // Get the instance manager.
var nMaxCount = oManager.occur.max; // Get the maximum number of subform occurrences allowed.
var nSubCount = oManager.count; // Get the current number of instances.
// Proceed if the maximum number of subform occurrences has not been reached.
if ((nMaxCount == "-1") || (nSubCount < nMaxCount)) {
// Invoke the Instance Manager.
var oNewInstance = oManager.addInstance(1);
// Move the new subform below the current one.
var nIndexFrom = oNewInstance.index;
var nIndexTo = oTargetSubform.index + 1;
oManager.moveInstance(nIndexFrom, nIndexTo);
} else {
xfa.host.messageBox(message,"Insert Item", 3);
}
// END OF DO NOT MODIFY
}
Delete row:
function deleteRow(deleteButton){
var message = "You have reached the minimum number of items allowed.";
// Fix for listener problem.
// Note that we're calling this before we delete the current node, BUT that's okay because the recalculate actually is
// deferred until after the current script finishes.
// DO NOT MODIFY THE CODE BEYOND THIS POINT - 8.2.1.3158.1.475346.466429 - Subform_Instance_Controls_IRM.xfo.p4
var oTargetSubform = deleteButton.parent.repeatingTable.repeatingRow; // The subform or table row the controls are intended to manipulate.
var oManager = oTargetSubform.instanceManager; // Get the instance manager.
var nMinCount = oManager.occur.min; // Get the minimum number of subform occurrences allowed.
var nSubCount = oManager.count; // Get the current number of instances.
// Proceed if the minimum number of subform occurrences has not been reached.
if (nSubCount > nMinCount) {
// Invoke the Instance Manager.
oManager.removeInstance(oTargetSubform.index);
} else {
xfa.host.messageBox(message,"Remove Item", 3);
}
// END OF DO NOT MODIFY
}