Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Displaying a hidden field, once it has data.

Avatar

Level 2

I have a radio button used to show/hide a comment field.  Initially the comment field’s presence is “hidden, exclude from layout” so that when the form opens, the
comment field does not show.  When the radio button is checked, the comment field then displays. Problem:  Once the user selects the radio button and enters
data into the comment field and saves it, how do you get the comment field to display every time the form is opened thus ignoring the “hidden, exclude from layout”
setting?  

Thank you

1 Accepted Solution

Avatar

Correct answer by
Level 2

No you should be fine there. I believe I misinterpreted your intent from your code...

This is the code you want to use:

if (this.rawValue == 1)  {

     this.resolveNode("RAConcur.Comments").presence="visible";

}

Just make sure you place the code into the change event of your radio button and that the value of your radio button actually does evaluate to 1.

View solution in original post

11 Replies

Avatar

Level 2

I have the same issue, but I hadn't thought of that scenario until I read your question, so thank you!

You can add some JavaScript code to the initialize event of the comment field, which will be triggered when the form is first opened. It can then check whether the radio button is checked and make the field visible if it is, something like this:

var choice = this.resolveNode("RadioButtons.Choices").rawValue;

if (choice == 1) {

  this.presence = "visible";

}

Avatar

Level 2

Thank you so much for your response.  I am using Acrobat Livecycle Designer and know nothing about scripting. Is this Script that is recognized in Acrobat LIVECYCLE?  Since I am unfamiliar I don't know if I edited it incorrectly, because it did not work for me. 

RAConcur.Comments is the name of the radio button that opens the Comment field.

I placed the following script on the Comment field that I want displayed if it has data when the form is opened.

var choice = this.resolveNode("RAConcur.Comments").rawValue;

if (RAConcur.Comments == 1) {

this.presence = "visible";

Avatar

Level 2

I also tried the following on the comment field, initialize event.

if  (this.rawValue==1) then

this.presence="visible" else

this.presence="hidden"

endif


Avatar

Level 2

Yes, LiveCycle Designer does JavaScript, as well as FormCalc. Just make sure that the Language drop-down at the top of the script window says "JavaScript" rather than "FormCalc". If it doesn't, change it.

You had left off the closing curly brace at the end, and you were trying to use the node name rather than the variable name in the if statement. The code would need to be more like this:

var choice = this.resolveNode("RAConcur.Comments").rawValue;

if (choice == 1) {

    this.presence = "visible";

}

If that still doesn't work, we're probably referencing the checkbox incorrectly. To make sure we have it correct, delete this.resolveNode("RAConcur.Comments"), leaving the ".rawValue" in place. Then, with the cursor just before the period at the start of ".rawValue", hold down the Ctrl key and click on the checkbox. That will insert into your code the proper reference to the checkbox field. It might be something like xfa.resolveNode("RAConcur.Comments"), or it might be something like Section1.RAConcur.Comments (without the need to have "xfa.resolveNode" at all). In any case, immediately after that should be the .rawValue.

I'm assuming that, when the Comments checkbox is checked, the value is 1. You can verify this by selecting the checkbox, then looking in the Binding tab of the Object pallet. The value for On is probably 1. If you're using a different value, you'll need to change your code to match.

Avatar

Level 2

Thank you for getting back to me. I entered the script, on Initialize, on the Comments field, JavaScript. (no errors) but does not seem to do anything.

The comment field has a Presence of “hidden” on the form field object. I have it hidden so it does not display when the form first opens. Could that be the problem? How can I accomplish both?

1. Comments hidden when the form first opens. (accomplished by setting the object property for presence = hidden).

2. Comments displays when RadioButton#2Comments is selected. (accomplished by javascript on radio button #3, when selected it displays the comment field)

3. Comments displayed when the form is reopened, because it has data. (not working because object property presence = hidden? Seems to ignore the VarChoice script on the comment field.)

4. Brings up another issue: If Radiobutton #2 is deselected (but comment data is not deleted) comments are hidden, but then they will just reappear if we get item #3 working. Which means we need code to delete the data if radiobutton#1Concur is selected.

Maybe I can’t have it all these different ways? I appreciate you trying to help me through this.

Bernadette Yu

FYI - For Your Information, Inc.

11785 Beltsville Drive, #120

Beltsville, MD 20705

301.586.8500 Fax 301.586.8400

http://www.fyinfo.com<http://www.fyinfo.com/>;

Avatar

Level 2

re: " Seems to ignore the VarChoice script"

You might have misread what I typed. That should be 2 words, "var" and "choice". The "var" stands for "variable" and means that what follows next is the name of a new variable. The name of the variable is "choice".

Could you copy and paste the script here, so I can see what you have entered?

Avatar

Level 2

var choice = this.resolveNode("RAConcur.Comments").rawValue

if (choice==1){

this.presence="visible"

}

Bernadette Yu

FYI - For Your Information, Inc.

11785 Beltsville Drive, #120

Beltsville, MD 20705

301.586.8500 Fax 301.586.8400

http://www.fyinfo.com<http://www.fyinfo.com/>;

Avatar

Level 2

You are missing your semicolons.

var choice = this.resolveNode("RAConcur.Comments").rawValue;

if (choice == 1)

     this.presence = "visible";

Livecycle is a poor place to learn proper javascript syntax as it is not a proper editor. Try some quick online courses to get some of the basics down and I can assure you'll have a much better experience.

Avatar

Level 2

It sill does not work, but I think maybe because the object's property (comment field) for presence = hidden (from layout).  But that is needed so the field is hidden upon opening the blank form.

Thank you,

Bernadette Yu

FYI - For Your Information, Inc.

[personal info removed in accordance with forum rules}

http://www.fyinfo.com

Avatar

Correct answer by
Level 2

No you should be fine there. I believe I misinterpreted your intent from your code...

This is the code you want to use:

if (this.rawValue == 1)  {

     this.resolveNode("RAConcur.Comments").presence="visible";

}

Just make sure you place the code into the change event of your radio button and that the value of your radio button actually does evaluate to 1.

Avatar

Level 2

Thank you so much for your patience and working with me!  You did it!  You fixed my problem and your script works perfectly.  Thank you so much!!!