Expand my Community achievements bar.

SOLVED

Problem with removing the first table row

Avatar

Former Community Member

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 hererow 1
Add and delete buttons hererow 2
Add and delete buttons hererow 3

If the user deletes row 2 the table looks like this which is correct:

Column 1
Column 2
Add and delete  buttons hererow 1
Add and delete buttons hererow 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 hererow 1
Add  and delete buttons hererow 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

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

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

View solution in original post

5 Replies

Avatar

Former Community Member

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

Avatar

Former Community Member

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

Avatar

Former Community Member

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.

Avatar

Correct answer by
Former Community Member

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

Avatar

Former Community Member

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

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----