Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

If one checkbox of 15 is checked then show/hide a field

New Here ,
May 24, 2019 May 24, 2019

I have a group of 15 check boxes, if one of them (or more) is checked, then I would like field to show. If none are checked, the field disappears. How would I do this?

Additionally, if the check boxes and fields are updated (if spawned), how would this work?

TOPICS
Acrobat SDK and JavaScript , Windows
2.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 28, 2019 May 28, 2019

Sorry, first line should be:

var baseName = event.target.name.replace("User1_Reporting_Cover", ""); 

Translate
Community Expert ,
May 24, 2019 May 24, 2019

The first part is quite simple, but the second part is much more complicated.
Regarding the first: What are the names of those check-boxes, and of the field to show/hide?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 24, 2019 May 24, 2019

The names of the check boxes are as follows: "User1_Account1_Reporting", "User1_Account2_Reporting", "User1_Account3_Reporting", "User1_Account4_Reporting", through "User1_Account15_Reporting".

The field is called "User1_Reporting_Cover"

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 24, 2019 May 24, 2019

OK. You can use this code as the custom calculation script of "User1_Reporting_Cover", then:

var bShow = false;

for (var i=1; i<=15; i++) {

    if (this.getField("User1_Account"+i+"_Reporting").valueAsString!="Off") {

        bShow = true;

        break;

    }

}

event.target.display = bShow ? display.visible : display.hidden;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 28, 2019 May 28, 2019

Great thanks try67​!

To my other point, upon spawning a new blank template, how would this work to update the field titles?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 28, 2019 May 28, 2019

That's much more complicated. You would need to study how the fields are named on spawned pages and then adjust your code to be able to handle that.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 28, 2019 May 28, 2019

Can you give me a sample code that I can adjust to?

My code spawns as follows: P3.User_Page1.User1_Wire_Cover

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 28, 2019 May 28, 2019

Try this:

var baseName = event.target.replace("User1_Reporting_Cover", "");

var bShow = false;

for (var i=1; i<=15; i++) {

    if (this.getField(baseName + "User1_Account"+i+"_Reporting").valueAsString!="Off") {

        bShow = true;

        break;

    }

}

event.target.display = bShow ? display.visible : display.hidden;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 28, 2019 May 28, 2019

the debugger says that "event.target.replace" is not a function.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 28, 2019 May 28, 2019

Sorry, first line should be:

var baseName = event.target.name.replace("User1_Reporting_Cover", ""); 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 28, 2019 May 28, 2019

Great, that worked!! I'm all set for fields, but if one of those fifteen checkboxes were selected (on a spawned page) how would it trigger a checkbox (as you cannot calculate a checkbox)?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 28, 2019 May 28, 2019

You can do it using the calculation event of a text field.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 02, 2019 Jun 02, 2019

try67​ - the problem is that the field shows, but the checkboxes do not show.

If one of the 15 checkboxes is clicked, how do additional checkboxes show up? I'm trying to leverage the following code (that will be added to each of the 15 checkboxes):

var aParts = event.targetName.split(".");

aParts.pop();

var cPrefix = aParts.join(".");

for (var i=1; i<=15; i++) {

if (this.getField(cPrefix+".User1_Account"+i+"_Wire").valueAsString!="Yes")

{

this.getField(cPrefix+".User1_Wire_Create").display = 0;

this.getField(cPrefix+".User1_Wire_OneTime").display = 0;

this.getField(cPrefix+".User1_IFT_Approval").display = 0;

this.getField(cPrefix+".User1_Wire_FileImport").display = 0;

this.getField(cPrefix+".User1_Wire_TemplateImport").display = 0;

this.getField(cPrefix+".User1_Wire_ReleaseCancel").display = 0;

this.getField(cPrefix+".User1_Wire_TemplatePayees").display = 0;

this.getField(cPrefix+".User1_Wire_ActivityAudit").display = 0;

this.getField(cPrefix+".User1_Wire_TemplateMaintenance").display = 0;

this.getField(cPrefix+".User1_Wire_ApprovalRelease").display = 0;

this.getField(cPrefix+".User1_Wire_Daily Transaction Debit Amount Per Account").display = 0;

this.getField(cPrefix+".User1_Wire_Daily Transaction Count Per Account").display = 0;

this.getField(cPrefix+".User1_Wire_Single Transaction Debit Amount").display = 0;

this.getField(cPrefix+".User1_Wire_DefaultCover").display = 1;

this.getField(cPrefix+".User1_Wire_NoApprovers").display = 0;

this.getField(cPrefix+".User1_Wire_OneApprover").display = 0;

this.getField(cPrefix+".User1_Wire_OneApprover_Amount").display = 0;

this.getField(cPrefix+".User1_Wire_TwoApprover").display = 0;

this.getField(cPrefix+".User1_Wire_TwoApprover_Amount").display = 0;

}

else

{

this.getField(cPrefix+".User1_Wire_Create").display = 1;

this.getField(cPrefix+".User1_Wire_OneTime").display = 1;

this.getField(cPrefix+".User1_IFT_Approval").display = 1;

this.getField(cPrefix+".User1_Wire_FileImport").display = 1;

this.getField(cPrefix+".User1_Wire_TemplateImport").display = 1;

this.getField(cPrefix+".User1_Wire_ReleaseCancel").display = 1;

this.getField(cPrefix+".User1_Wire_TemplatePayees").display = 1;

this.getField(cPrefix+".User1_Wire_ActivityAudit").display = 1;

this.getField(cPrefix+".User1_Wire_TemplateMaintenance").display = 1;

this.getField(cPrefix+".User1_Wire_ApprovalRelease").display = 1;

this.getField(cPrefix+".User1_Wire_Daily Transaction Debit Amount Per Account").display = 1;

this.getField(cPrefix+".User1_Wire_Daily Transaction Count Per Account").display = 1;

this.getField(cPrefix+".User1_Wire_Single Transaction Debit Amount").display = 1;

this.getField(cPrefix+".User1_Wire_DefaultCover").display = 1;

this.getField(cPrefix+".User1_Wire_NoApprovers").display = 1;

this.getField(cPrefix+".User1_Wire_OneApprover").display = 1;

this.getField(cPrefix+".User1_Wire_OneApprover_Amount").display = 1;

this.getField(cPrefix+".User1_Wire_TwoApprover").display = 1;

this.getField(cPrefix+".User1_Wire_TwoApprover_Amount").display = 1;

}

}

Any help is greatly appreciated!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 03, 2019 Jun 03, 2019

There's really no need to place the code on each one of the check-boxes. Just use the calculation script of a (hidden) text field.

Also, I believe this code you found is for a spawned page. You don't need that. Just use the names of the fields directly.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 03, 2019 Jun 03, 2019

Ok - what would the code look like?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 03, 2019 Jun 03, 2019

Sorry, I went back and I do see that you want to do it as a part of spawned page. In that case just put the code you have as the custom calculation script of a text field (that is located on the Template page) and I think it should work.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 03, 2019 Jun 03, 2019

Unfortunately the check boxes do not disappear when I do this.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 03, 2019 Jun 03, 2019

Are there any errors in the JS Console? Can you share the file in question?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 03, 2019 Jun 03, 2019

what is your email? I will send the form. I your scroll down to the user set up, as you can see the checkboxes are not disappearing when needed (for wires), I would like this to do this for all the subsequent sections and when this is spawned over and over again.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 03, 2019 Jun 03, 2019
LATEST

You can send it to [try6767 at gmail.com].

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines