This conversation has been locked due to inactivity. Please create a new post.
This conversation has been locked due to inactivity. Please create a new post.
Hi All,
I have a problem with my forms with tables where I have buttons to add or remove table rows. Adding rows works great but deleting rows has a problem when deleting the first row. Example: here is a table with two rows where column 1 has the add and delete buttons and column 2 has user imput which looks something like this:
Column 1 | Column 2 |
---|---|
Add and delete buttons here | row 1 |
Add and delete buttons here | row 2 |
Add and delete buttons here | row 3 |
If the user deletes row 2 the table looks like this which is correct:
Column 1 | Column 2 |
---|---|
Add and delete buttons here | row 1 |
Add and delete buttons here | row 3 |
If the user deletes row 1 then the table looks like this which is wrong since row 2 and 3 should be left:
Column 1 | Column 2 |
---|---|
Add and delete buttons here | row 1 |
Add and delete buttons here | row 3 |
The code is pretty straight forward:
Table3.Row2.instanceManager.addInstance(1); for the click event of the add row button
Table3.Row2.instanceManager.removeInstance(1); for the click event of the delete row button
What am I doing wrong?
Thanks in advance!
Al
Solved! Go to Solution.
Views
Replies
Total Likes
The expression will be based on your structure .....this refers to the current object, parent refers to the parent container of this object and index is the index of that object. So looking at your hierarchy and starting from the button you will need this.parent to get to the row subform that it is in (typically that is th esubform that is repeating). If that is in another subform you will need to add another parent. Continue down this path until you get to the repeating subform and then ask for its index. Your expression may look like this.parent.parent.parent.index. By using this.index you are getting the instance of the button object and there are only of those so that is why you are always getting 0.
Make sense?
BTW your form is not attached...so I cannot verify what you shoudl be putting in there.
Paul
Views
Replies
Total Likes
The removeInstance methods needs the subform index to remove. By placing a 1 in there you are always removing the 2nd instance (indexes are 0 based). So what you need is the index of the instance that you areon. You can get this by using this.parent.index (I am assuming that your buttons are 1 subform level deep in the hierarchy from the repeating subform). So combining this together your remove command shoudl be:
Table3.Row2.instanceManager.removeInstance(this.parent.index);
Paul
Thanks Paul,
When I point to this.parent.index I get this error: "Argument mismatch in property or function argument"
However, when I use this.parent.instanceindex it always removes the first table row. The same thing happens when I use this.index.
I guess I need to know the index of the of the row I'm deleting. I tried to use resolvenode but the function does not seem to work with the index argument - resolvenode(this).index returns an error.
Is there a function to return the index of the table row?
I'll email the form to you.
Cheers,
Al
Views
Replies
Total Likes
Hi Paul,
I added another post to the discussion. I still can't resolve the index of
the table row I'm trying to delete. Using this.index as the argument to
removeinstance() always removes row 0 until minimum rows are left.
I attached my form; hope you can help.
Cheers,
Al
PS I noticed there is another discussion posted with the same question.
Views
Replies
Total Likes
The expression will be based on your structure .....this refers to the current object, parent refers to the parent container of this object and index is the index of that object. So looking at your hierarchy and starting from the button you will need this.parent to get to the row subform that it is in (typically that is th esubform that is repeating). If that is in another subform you will need to add another parent. Continue down this path until you get to the repeating subform and then ask for its index. Your expression may look like this.parent.parent.parent.index. By using this.index you are getting the instance of the button object and there are only of those so that is why you are always getting 0.
Make sense?
BTW your form is not attached...so I cannot verify what you shoudl be putting in there.
Paul
Views
Replies
Total Likes
Thanks Paul!
That was the problem. I was not going deep enough in the structure to identify the correct index. parent.parent.parent.index does work perfectly for my form.
Cheers,
Al
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies