Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Controlling a dynamic Table with a Checkbox (InstanceManager, moveInstance issue)

Avatar

Level 3

Hello,

I am having some problems in using InstanceManager (dynamic tables). I try to add and delete new rows by using checkboxes. If a checkbox gets clicked a new row, with a value given from the checkbox, appears. If a checkbox gets deactivated, then the row, it has created, is going to be removed.

I use addInstance to add new lines into the table. In this case new line apperas always at the end of the table, which is just perfect! It is exactly the way I need it. But I have no idea how to pass over the value of my checkboxes right to the last line of my table.

I have tried to use moveInstance an it just messed up my form. (uploaded here: www.hs-augsburg.de/~nikg-fh/mypdf.pdf )

My Form:

1.png

My Code:

MyForm.page1.checkbox1::change - (JavaScript, client)

if (this.rawValue == "1")
{
var myInstance = xfa.form.MyForm.page1.MyTable._MyRow.addInstance(1);
var fromIndex = xfa.form.MyForm.page1.MyTable._MyRow.index;
var toIndex = myInstance.index;
// Value of col. "CheckBox-Value"
    xfa.form.MyForm.page1.MyTable.MyRow.checkboxValue.rawValue = "CheckBox 1"; // <<<<<HERE IS THE PROBLEM!!!!!
// Value of col "fromIndex"
    xfa.form.MyForm.page1.MyTable.MyRow.fromIndex.rawValue = fromIndex;
// Value of col "toIndex"
    xfa.form.MyForm.page1.MyTable.MyRow.toIndex.rawValue = toIndex;
// Move Row
    xfa.form.MyForm.page1.MyTable._MyRow.moveInstance(fromIndex, toIndex);  // <<<< Don't need to use this Method?!
}
else
{
var rowToDelete = xfa.form.MyForm.page1.MyTable._MyRow.index;
    xfa.form.MyForm.page1.MyTable._MyRow.removeInstance(rowToDelete);
    xfa.form.MyForm.page1.deletedRow.rawValue = rowToDelete + 1;
}




it just gets messed up with this code, because of moveInstance (all checkboxes have similar coding):

any checkbox clicked:

1.png

checkbox1 klicked

2.png

checkbox 2 klicked:

3.png

checkbox 3 klicked:

4.png

0 Replies

Avatar

Level 10

Hi,

I don't think checkboxes are a very intuiative way for the user to add rows.

That said, the main issue is that you are not specifying which instance of MyRow you want to set the value of checkboxValue. So this line:

xfa.form.MyForm.page1.MyTable.MyRow.checkboxValue.rawValue = "CheckBox 1"

Would become:

var i = page1.MyTable._MyRow.count - 1;

xfa.resolveNode("page1.MyTable.MyRow[" + i + "]").checkboxValue.rawValue = "CheckBox 1";

Also I would place the script in the click event of the checkbox, as the change event uses "xfa.event.newText". The click event uses "this.rawValue" as you have it.

Hope that helps,

Niall