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

Help! javascipt and LiveCycle

Avatar

Former Community Member

I’ve got a little over three-months experience with Adobe LiveCycle. 

I have a row of three-text field items which I’d like to enable/disable based on a checkbox. 

So if Checkbox-1 == 0 then Field-1, Field-2, Field-3 will be disabled
else Checkbox-1 == 1 then Field-1, Field-2, Field-3 will be enabled & required

I'm also trying to determine which item under the "Show" drop down that this script will need to be placed.

Any help would be greatly appreciated,
Andy

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi Andy,

Here is a sample where the required status of the checkboxes changes if any one of them is checked: https://acrobat.com/#d=J0KsvCyW0s4qUECdSXMEdQ

You access the mandatory property - 'error' sets a field to required, whereas 'disabled' is not required. So this would make a textfield required:

TextField1.mandatory = "error";

Whereas this would make a field not required:

TextField1.mandatory = "disabled";

The other aspect you are looking for is whether the user can input data, which requires the access property. This makes the field available:

TextField1.access = "open"; 

Whereas this makes it unavailable:

TextField1.access = "readOnly"; 

So for your form, I would put the following script in the click event of the checkbox:

if (this.rawValue == "0")

{

     Textfield1.access = "readOnly";

     Textfield2.access = "readOnly";

     Textfield3.access = "readOnly";

     Textfield1.mandatory = "disabled";

     Textfield2.mandatory = "disabled";

     Textfield3.mandatory = "disabled";

}

else

{

     Textfield1.access = "open";

     Textfield2.access = "open";

     Textfield3.access = "open";

     Textfield1.mandatory = "error";

     Textfield2.mandatory = "error";

     Textfield3.mandatory = "error";

}

I hope that helps,

Niall

View solution in original post

5 Replies

Avatar

Correct answer by
Level 10

Hi Andy,

Here is a sample where the required status of the checkboxes changes if any one of them is checked: https://acrobat.com/#d=J0KsvCyW0s4qUECdSXMEdQ

You access the mandatory property - 'error' sets a field to required, whereas 'disabled' is not required. So this would make a textfield required:

TextField1.mandatory = "error";

Whereas this would make a field not required:

TextField1.mandatory = "disabled";

The other aspect you are looking for is whether the user can input data, which requires the access property. This makes the field available:

TextField1.access = "open"; 

Whereas this makes it unavailable:

TextField1.access = "readOnly"; 

So for your form, I would put the following script in the click event of the checkbox:

if (this.rawValue == "0")

{

     Textfield1.access = "readOnly";

     Textfield2.access = "readOnly";

     Textfield3.access = "readOnly";

     Textfield1.mandatory = "disabled";

     Textfield2.mandatory = "disabled";

     Textfield3.mandatory = "disabled";

}

else

{

     Textfield1.access = "open";

     Textfield2.access = "open";

     Textfield3.access = "open";

     Textfield1.mandatory = "error";

     Textfield2.mandatory = "error";

     Textfield3.mandatory = "error";

}

I hope that helps,

Niall

Avatar

Former Community Member

Worked perfectly! Just had to copy the first part of the if statement to the initialize so the form was disabled on load until a user selects the appropriate check box.

Thanks again,
Andrew

Avatar

Former Community Member

The code above worked great for single checkbox(s) but I have a radiobutton which I’d like to produce similar results. 

My radio button has seven-options and two of them I’d like to require additional information if selected.

If (this.rawValue == “6”,”7”)
{
TextField6.access == “readOnly”;
TextField6.mandatory ==”disabled”;
TextField7.access == “readOnly”;
TextField7.mandatory ==”disabled”;
}
else
{
TextField6.access = “open”;
TextField6.mandatory = “error”;
TextField7.access = “open”;
TextField7.mandatory = “error”;
}

I’m trying to input this script into the ‘RadioButton1’ however it doesn’t appear that I can do this…do I have to edit each “button”? Such as RadioButton1.First and so on and input the code…that didn’t work either….

Any help would be a tremendous time saver,
Andrew

Avatar

Level 10

Hi Andrew,

When dealing with radiobuttons it is best to place the script in the click event of the radio button group and not the individual radio buttons.

When testing against multiple conditions you need to explicitly state each one. For example a radio button group can only have one value so you are looking to see if it is '6' or '7'.

Please note that && means 'and', || means 'or'

if (this.rawValue == “6” || this.rawValue == ”7”)
{
     TextField6.access == “readOnly”;
     TextField6.mandatory ==”disabled”;
     TextField7.access == “readOnly”;
     TextField7.mandatory ==”disabled”;
}
else
{
     TextField6.access = “open”;
     TextField6.mandatory = “error”;
     TextField7.access = “open”;
     TextField7.mandatory = “error”;
}

You can build more complex tests by wrapping in brackets:

if (TextField1.rawValue == "Apples" || (TextField1.rawValue == "Oranges" && DropDown1.rawValue == "Not in stock"))

{

     ...

}

Hope that helps,

Niall