Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.

Can you change the caption of a button with a script?

Avatar

Former Community Member
I thought it might be possible to script a button caption so I could have a button that says "Hide Field" when a field is visible then "Show Field" if the field is hidden or invisible.



I found the following line of a code in the Designer help.



Button1.caption.value.#text = "text"



But also found it written this way in another part of the help.



Button.caption.#text.value = "text"



I tried both and neither does anything.
8 Replies

Avatar

Former Community Member
If you're using FormCalc it's:



Button1.caption.value.#text = "text"



But it will only work in a dynamic PDF, not a static one.



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
What about JavaScript? I was hoping to be able to put this in with the other line of script that hides or shows the field. I am working with a dynamic PDF. There seems to be a typo in the help.

Avatar

Former Community Member
'#' is an illegal character in JavaScript so you need to use resolveNode. It should be:



Button1.caption.value.resolveNode("#text").value = "text";



Can you tell me where in the help you found the script that shows it incorrectly? I haven't been able to find it.



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
So it's that resolveNode thing again. I'm just not getting the use of that thing. When to use it that is. Thanks I will give it a try.



The two places in the help that I looked are as follows. I opened up the help and went to the contents tab.



Contents > Object Scripting Reference > Scripting Properties > #text property



and



Contents > Object Scripting Reference > Button scripting properties > Button object field properties.



Hope I got the paths right for you.

Avatar

Former Community Member
Thanks I found the two places you were looking at.



If you're interested it's not a bug or type-o, though it may be a bit hard to understand. In the button specific help location it has the proper statement. The other one is about using the #text property in general (it's not really that helpful since it will be different for all sorts of real situations). Anyways what it lists is:



SOMExpression.#text.value = "text"



Which is perfectly valid since you need to replace SOMExpression by the proper expression depending on what you're working with. In your case it's the button's caption, so you replace SOMExpression with Button1.caption.value.



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
Thanks for clearing that up. It was a bit confusing. Must be for real programers which I'm not. Would like to be some times.



The line using resolveNode worked. Although I don't fully understand what is going on with ".value" in there twice.



But anyway I sure do appreciate your help on this forum.

Avatar

Former Community Member
When working with a DOM (Document Object Model, basically an XML tree), .value refers to the value of an XML node. So:

Blah Blah

In this case if you wanted to reference "Blah Blah" it would be SomeNode.value.

FormCalc has more direct access to the DOM, so if you don't add the .value to the end it's smart enough to figure out that that's what you want (but you can still specify it explicitly if you want). JavaScript doesn't have that advantage so you must specify .value.

So, in FormCalc:

SomeNode == SomeNode.value == "Blah Blah"

whereas, in JavaScript:

SomeNode == [an XFA object] (not a specific value)
SomeNode.value == "Blah Blah"

Hope that helps explain it a bit.

Chris
Adobe Enterprise Developer Support

Avatar

Former Community Member
Yes thank you.



When does the book come out? We need a good book with examples and explanations.