cancel
Showing results for 
Search instead for 
Did you mean: 

Scripting in Adobe Forms - Hiding a field

Former Member
0 Kudos

Hi Experts

I have some code that I just can't get to work - please advise where I am going wrong.

Looking at the folowing code segment (Javascript, at Client), I am running through a loop of items (PO Text Items). If I take the IF statement out around the statement where I hide the fields, it works well (in other words it hides every line), but I only want to hide lines where the item (ItemTextFromPO) is empty.


var oFields = xfa.resolveNodes("data.PO_Page.MainSubform.ItemSubForm.POItemText.DATA[*].ItemTextFromPO");
var nNodesLength = oFields.length;
for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++) 
	{
	if ( xxxxxxxxxxxx.rawValue == "" )
		{
		oFields.item(nNodeCount).presence = "hidden";
		}
	}

Please advise what I need to use in the IF statement to make it work?

Thanks

Casper

Accepted Solutions (1)

Accepted Solutions (1)

OttoGold
Active Contributor
0 Kudos

Hello,

there is a simple and effective approach for your problem. You don´t have to do any loop. Just place a script on the repeating subform and it will be called for every data item for which a new instance of your subform is created. If you have 5 items, it will be called 5 times automatically.

Script like this: if (this.youfieldname.rawValue == null) this.presence = "hidden"; //this pointer can be used in JS scripting only and means (in this case) the subform (the repeating one) which wraps in the line. Relative addressing can be very useful, so note there is this "this" pointer and also a "parent" pointer (yourfield.parent points to the parent subform).

Hope this will solve your problem,

regards Otto

Former Member
0 Kudos

Hi Otto

Thanks - I will try, and revert. I am just busy with something else right now, but I will try soon and award points if useful.

I must say that I tried putting it on the subform initially (for that exact reason!), but I did not use 'this' - I used direct adressing - and maybe that is where it went wrong. I will try your suggestion later today and let you know.

Thanks,

Casper

Answers (3)

Answers (3)

OttoGold
Active Contributor
0 Kudos

Glad to help, but Chintan is the Man as well:)) Have a nice day, everybody, Otto

OttoGold
Active Contributor
0 Kudos

I can recommend you to use this relative addressing every time you can, because:

a) it spares a lot of time

b) it will spare you a lot of debugging and doing changes when anything in your form (and in your data!! that happens quite often when somebody else changes your data structures -at least on my project:)) changes

Have a nice day, Otto

Former Member
0 Kudos

OK, so Otto is the man.

Thanks - that solved it. I think, actually, that my old solution would have worked, but I always used == "" in the condition, which did not work in this situation, but has worked before for another problem... Now, for this problem, I tried == null, and it worked perfectly.

Anyway, it now works with relative addressing and == null , so full points awarded.

Thanks for the feedback and the answer.

Kind regards,

Casper

chintan_virani
Active Contributor
0 Kudos

May be you can try putting the if outside the for loop i.e.

if(condition)
{
    //for loop logic.
}

Chintan

Former Member
0 Kudos

Hi Chintan

Thanks, but I'm afraid that doesn't do the trick - I need to be able to access every item with a table index, and outside the loop that index is possibly not visible (depending on where you declare it), or it is always the same.

Therefore, I will not be accessing the individual items, each one of which could be different.

Thanks though,

Casper

chintan_virani
Active Contributor
0 Kudos

But there is no index in the if statement you have written. Can you please explain your scenario in detail as that will help in how to write the JS.

Chintan

Former Member
0 Kudos

Hi Chintan

I know there is no index currently in the if statement - and that is my problem.

I am getting a table of texts for PO Items passed into a form. Some items may have more than one text item, and some may have none. For those with none, it will still have a dummy entry - i.e. a table entry with nothing next to it. A table might look like this:

0010 Text for item 10

0010 More text for item 10

0020

0030 Text for item 30.

So, Item 20 above has no text (an empty text line).

In the form, I have a repeating subform - it repeats once for evry item. On this subform, I have an textfield called that can repeat many times, if necessary (like for Item 10 above in this example). In the context of the form, I have a where condition that linke the item texts to the items - in other words the texts appear with the correct items already.

However, I do not want anything to appear if the field is empty (like for line 20, in this example).

So, I have written the loop as you saw in my original question. This loop works - if I take the IF statement out, then it hides EVERY line. If I do not use a loop, it only hides the 1st line... so the loop is required.

I then need to 'ask' each item with the IF statement whether it is empty or not - and if it is, then hide it. So, I just need someone to tell me the correct syntax for the xxxxxxxxxxxxx in my IF statement. This should surely include the index (the counter of the loop) somehow, so that I can access each individual item.

I have tried many combinations, but none worked - so far.

Please let me know if I need to explain more.

Thanks,

Casper