Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

changing a text field caption based on two fields

Avatar

Level 7

This one is kinda complicated (to me anyway). So, bear with me on this while I try to properly explain it.

Problem: I have two fields tfLastName and tfFirstName--in that order. I have another field tfSignatureLine. I need the caption on tfSignatureLine to change based on the value of the first and last name fields.

Attempt to solve: Both fields have an exit script. This is the exit script for tfLastName.

if (!this.isNull && !this.parent.tfFirstName.isNull){ //first check to see that both fields have something in them.

          var name = this.parent.tfFirstName.rawValue + " " + this.rawValue; //create a variable that combines the values of the fields

          this.parent.parent.tfSignature1.resolveNode("caption.value.#text").value = name; //change the caption to the name

}

Of course, the exit script for tfFirstName has the appropriate if statement for checking it and tfLastName.

Error (run time): When filling out the fields, the second field to be exited is the only one that will update the name.

Example: Suppose you're filling out a form for John Smith. So, you enter "Smith" in tfLastName and "John" in tfFirstName. tfSignatureLine now says "John Smith".

Then he says, "BTW, that's 'Jon' with no 'h.'" So, you update that field. tfSignatureLine says, "Jon Smith".

Then he says, "and that's 'Smyth' with a 'y' instead of an 'i'." You update tfLastName and exit the field. tfSignatureLine does not get updated. I still says "Jon Smith". You continue and exit tfFirstName. THEN tfSignatureLine gets updated.

If you reverse the order (maybe you know how to spell the first name but not the last, so you start there), tfFirstName will not update tfSignatureLine, but tfLastName will.

Ideas: It almost feels like the problem is with using "resolveNode" to get the caption into the code. I couldn't find another way to change the caption without it, though. Is there something I've missed as I've looked into this? Maybe something like "this.caption.value" or "this.caption.rawValue". Those don't seem to work, so I'm guessing it's not those specifically. Before I had the if statement, tfSignatureLine would have gotten "null Smith" as it's value.

1 Accepted Solution

Avatar

Correct answer by
Level 10

I think there's something up with your resolveNode syntax. Not sure it works properly with things like this.parent.parent, etc. But someone may feel free to correct me on that point.

I couldn't take a good look at your file because it looks like you've used fragments and you have to embed them in the document for other people to see them.

The following works:

if (!this.isNull && !tfLastName.isNull){

          var name = this.rawValue + " " + tfLastName.rawValue;

          tfSignature1.resolveNode("caption.value.#text").value = name;

}

But I never use resolveNode() like that, so am unsure of the syntax. I always use xfa.resolveNode() like:

xfa.resolveNode("Path.To.FieldName.caption.value.#text").value

You probably don't need the "parent" references in your form. The best way to get the path to a field is to use the CTRL key to click on an object while you are in the Script Editor.

View solution in original post

6 Replies

Avatar

Level 7

@vipin

That is almost a perfect example of what is happening. You're changing the text field's value instead of the caption, but the same problem is occuring. Whichever field you fill out second will be the only field that can update the signature.

Here's a more accurate example of what I'm trying to do.

https://workspaces.acrobat.com/?d=nbnDnIvVqF-Geqhiv2fAOw

I included the code for each text field in the PDF as well as instructions and a theory of what causes the issue: It feels like once the last line in the if statement occurs, the node is resolved inside the tfFirstName::exit event, and it cannot be resolved inside another event in the same instance of the form. Is that a known limitation that I just don't know about?

Avatar

Correct answer by
Level 10

I think there's something up with your resolveNode syntax. Not sure it works properly with things like this.parent.parent, etc. But someone may feel free to correct me on that point.

I couldn't take a good look at your file because it looks like you've used fragments and you have to embed them in the document for other people to see them.

The following works:

if (!this.isNull && !tfLastName.isNull){

          var name = this.rawValue + " " + tfLastName.rawValue;

          tfSignature1.resolveNode("caption.value.#text").value = name;

}

But I never use resolveNode() like that, so am unsure of the syntax. I always use xfa.resolveNode() like:

xfa.resolveNode("Path.To.FieldName.caption.value.#text").value

You probably don't need the "parent" references in your form. The best way to get the path to a field is to use the CTRL key to click on an object while you are in the Script Editor.

Avatar

Level 10

Hi, Not sure it would be causing your problem but I would avoid using "name" as a local JavaScript variable.  It can cause a name conflict with the name property of the XFA object containing the script. Bruce

Avatar

Level 7

Here's what ended up working in case anyone else ever needs this.

var n = "";

 

if (!this.isNull && !tfLastName.isNull){

     n = this.rawValue + " " + tfLastName.rawValue;

}

else{

     n = "Customer Signature";

}

 

xfa.resolveNode("tfSignature.caption.value.#text").value = n;