Expand my Community achievements bar.

SOLVED

Check if any instances of a field in a table are empty?

Avatar

Level 2

I'm having an issue with checking if any the instances of a field within a table are empty. If any are empty I need a message box to appear. There's one header row and one body row with several text fields. The body row is set to repeat and there are buttons to add and remove body rows.

I have had success in checking if any fields are empty in the initial row by using the following code:

if ((this.resolveNode("Page1.Table1.Row3.TextField1").rawValue == null || this.resolveNode("Page1.Table1.Row3.TextField1").rawValue == "") || (this.resolveNode("Page1.Table1.Row3.TextField2").rawValue == null || this.resolveNode("Page1.Table1.Row3.TextField2").rawValue == "") || (this.resolveNode("Page1.Table1.Row3.TextField3").rawValue == null || this.resolveNode("Page1.Table1.Row3.TextField3").rawValue == "") || (this.resolveNode("Page1.Table1.Row3.TextField4").rawValue == null || this.resolveNode("Page1.Table1.Row3.TextField4").rawValue == ""))

{xfa.host.messageBox("Please complete the Evaluation/Implementation table.", "Form Incomplete", 1);}

I'm guessing that for all instances to be checked I must use the "resolveNodes" function however I haven't been able to get it to work. This is what I've tried:

if ((this.resolveNodes("Page1.Table1.Row3.TextField1").rawValue == null || this.resolveNodes("Page1.Table1.Row3.TextField1").rawValue == "") || .........)

Although this doesn't work since .rawValue isn't a function that work with resolveNodes (only resolveNode).

What code should I be using for this?

Thanks in advance for any advice.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi there,

To be able to verify each fields in a multiple row instances of a table, you must specify which row you are trying to access...

To do so, you need to specify the row's index, this way you can treat each rows within a loop and access each fields inside that row

Instead of using resolveNodes, I suggest you use resolveNode.. and it should look something like this :

Hope this help!

View solution in original post

6 Replies

Avatar

Correct answer by
Level 10

Hi there,

To be able to verify each fields in a multiple row instances of a table, you must specify which row you are trying to access...

To do so, you need to specify the row's index, this way you can treat each rows within a loop and access each fields inside that row

Instead of using resolveNodes, I suggest you use resolveNode.. and it should look something like this :

Hope this help!

Avatar

Level 2

Thanks for the reply, this method seems more promising than what I have tried but unfortunately the message box doesn't show up using this pattern of code. I haven't worked with variables much before either but I understand some basics... The part confusing me is in the square brackets of each resolveNode part.

Is there something above you might have coded wrong as I`m not used to some of coding you`re using?

Thanks for your help.

Avatar

Level 10

The square braquets are used to specify which instances you want to access...

Row3 is the name of your row, but you have multiple instances of that object... so to be able to access the right Row3 that you want you need to specify which one...

When you have 1 instance of Row3, its name stays the same

But when you have multiple instances of Row3, their names changes to Row3[0], Row3[1], Row3[2]... etc.

Make sure your if statement is exactly how you want it and that you removed the dots at the end, also make sure that you renamed your Page3

The if statement I provided has a minor error which I don't validate the TextField2 to null, but you should change that statement to your likings...

If you have no idea what could be wrong, paste in your code I'll have a look!

Avatar

Level 2

Thanks for the effort in helping me out. Now that I understand the code a little better I tried messing around with it but still no message box.

Should anything be different since this is within the postSave event of the form?

I thought maybe the '.TextField1' might have to be in the () brackets of resolveNode after the [] brackets but that didn't work either.. tried removing possibly unneeded spaces I thought might be mistakes.

The code below is what I have now. Only posting half as it gets pretty lengthy but the table is now wrapped in a sub form which I've added in. (Entire form is WIP)


for (var i = 0; i < Page1.Table1._Row3.count; i++){



if (this.resolveNode("Page1.Subform1.Table1.Row3[" + i.toString() + "]").TextField1.rawValue == null || this.resolveNode("Page1.Subform1.Table1.Row3[" + i.toString() + "]").TextField2.rawValue == null || this.resolveNode("Page1.Subform1.Table1.Row3[" + i.toString() + "]").TextField3.rawValue == null || this.resolveNode("Page1.Subform1.Table1.Row3[" + i.toString() + "]").TextField4.rawValue == null)



{xfa.host.messageBox("Please complete the Evaluation/Implementation table.", "Form Incomplete", 1);



   break;}



Technically even this should work for TextField1 to 4..

Thank you.

Avatar

Level 10

Hi again,

you should use the Script Validator within LiveCycle, this could help you.

Make sure you can also look at the errors that your code can provide, make sure you have the debugger on in acrobat pro

Here is a link on how to enable JavaScript Debugger, follow the steps if you haven't enabled it... Adobe LiveCycle ES3 * JavaScript Debugging

If you see no error, on last resort if you find nothing you can use another JavaScript Validator on web which can find things that livecycle cannot find... Esprima: Syntax Validator

Hope it will help

Avatar

Level 2

Thanks for your help. Using the debugger it helped me isolate the issue as the table being wrapped in a sub form. Soon as I removed it and adjusted the code everything worked perfect.

Just wish I could keep that sub form as the form's hierarchy will be pretty confusing without it. If anyone knows a workaround let me know please.

Thanks again.