Expand my Community achievements bar.

Does anyone know if it's possible to have a conditional statement in the click event of a delete row button for a repeating table?

Avatar

Level 3

Hi,

I am hoping to have a message box appear when I delete a row of a repeating table (remove instance in the click event of a remove button in that row) ONLY when a certain field of that row is has an existing value. Looking at it the other way, I don't want the message box to appear if the field is empty and the user is just removing extra lines for a cleaner look. In this case, the field being checked for a value is called "DebitVal".

Any ideas?

Here is the script that I am trying to use in the click event:

if (ViolationsTable.ViolCorrSection.ViolationsText.DebitVal = "")

{

ViolationsTable.ViolCorrSection.instanceManager.removeInstance(parent.parent.index);

}

else

{

app.alert ("Important message here.");

ViolationsTable.ViolCorrSection.instanceManager.removeInstance(parent.parent.index);

}

Also, for reasons I won't get into here, it was necessary to have add and delete buttons for each row of the repeating table.

Thanks in advance!

Dave

4 Replies

Avatar

Level 10

Hi Dave,

You condition looks wrong to me, I would guess that the line

if (ViolationsTable.ViolCorrSection.ViolationsText.DebitVal = "")

should be something like

if (ViolationsTable.ViolCorrSection.ViolationsText.DebitVal.isNull)

Bruce

Avatar

Level 3

Hi Bruce,

I'm getting closer. I actually tried a variety of  expressions, such as "== null" and yours, but the problem persists.

I am settling on the following, but there is a hangup related to the field that is being looked at for the condition that I will explain in a minute. Here's the script:

if

(ViolationsTable.ViolCorrSection.ViolationsText.DebitVal.isNull || ViolationsTable.ViolCorrSection.ViolationsText.DebitVal.rawValue.length == 0)

{

ViolationsTable.ViolCorrSection.instanceManager.removeInstance(parent.parent.index);

}

else

{

app.alert ("Warning Statement);

ViolationsTable.ViolCorrSection.instanceManager.removeInstance(parent.parent.index);

}

What happens is that, no matter which row in my table I'm in when I click the remove instance button, the script is always looking to the DebitVal field in the first row of the table. So, if the first row is empty, the message box won't appear for the removal of any row in my table. If the first row has a value in DebitVal, then the deletion of any row in the table will trigger the message box.

I need a way to specify the script to look at the DebitVal field in the row that I am clicking in, without messing up the remove instance command.

Ideas?

Dave

Avatar

Level 10

Hi Dave,

You should be able to reference the DebitVal field you want by just leaving off the table and row controls, so maybe the following will work;

if (ViolationsText.DebitVal.isNull || ViolationsText.DebitVal.rawValue.length == 0) {

If DebitVal is a text field then rawValue will return an object if it is null and a string object if not.  If DebitVal is a decimal field then rawValue will return an object if it is null and a number object if not.

Maybe it would be better using the formattedValue property instead as this is always a string.

Bruce

Avatar

Former Community Member

Your issue is that you are not referencing the right instance of the field. The repeating subform that contains the field will have an occurance number on it so it shoudl be something like this:

ViolationsText[occurance number].DebitVal

To get the specific occurance number that you are on - you said that each row has a button that is being pressed to delete the row. If so you can use the expression this.parent.index to get the occurance number. Now we have to combine these two expressions in a string and get it resolved so when referencing the field use this expression:

xfa.resolveNode("ViolationsText[" + this.parent.index + "].DebitVal").rawValue

Hope that helps

Paul