How to hide similiar named fields on multiple pages that were spawned and bRenamed

Community Beginner ,
Aug 09, 2018

Copy link to clipboard

Copied

Hi all,

Can use same help on trying to hide fields on multiple pages that was created from a hidden template page. You would click on the 'ADD PAGE' Button where it has this javascript linked to it.

     this.getTemplate("Provider").spawn({nPage:this.numPages, bRename:true, bOverlay: false});

The fields on the hidden template page are prefaced with:

"P0.field_name"

Fields I want to hide are prefaced with:

"P0.Hidden.field_name"

When I click on the add page button, the above fields become prefaced (respectively):

"P#.Provider.P0.field_name"

"P#.Provider.P0.Hidden.field_name"

The # would represent the numbered page. So 'P1' after clicking 'ADD PAGE' button once, 'P2' after clicking 'ADD Page' button a second time.

I would like to now be able to hide all of the "P#.Provider.P0.Hidden" groups when I click on a 'HIDE' Button across all pages, no matter how many were created. The below script is using a hidden check box field to be able to turn on and off the hidden value using the same HIDE button. (just did it this way to test out various things)

     var oChkFld = this.getField("HiddenCheck"); 

     oChkFld.checkThisBox(0,!oChkFld.isBoxChecked(0));

     this.getField("P#.Provider.P0.Hidden").display = (oChkFld.value=="Off") ? display.hidden : display.visible;

What is the correct way to hide all of those fields across all pages when the # is an unknown?

Thanks!

Mike

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

I would use something like this:

for (var i=0; i<this.numFields; i++) {

    var f = this.getField(this.getNthFieldName(i));

    if (f==null) continue;

    if (/Hidden/.test(f.name)) f.display = display.hidden;

}

TOPICS
Acrobat SDK and JavaScript

Views

120

Likes

Translate

Translate

Report

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

How to hide similiar named fields on multiple pages that were spawned and bRenamed

Community Beginner ,
Aug 09, 2018

Copy link to clipboard

Copied

Hi all,

Can use same help on trying to hide fields on multiple pages that was created from a hidden template page. You would click on the 'ADD PAGE' Button where it has this javascript linked to it.

     this.getTemplate("Provider").spawn({nPage:this.numPages, bRename:true, bOverlay: false});

The fields on the hidden template page are prefaced with:

"P0.field_name"

Fields I want to hide are prefaced with:

"P0.Hidden.field_name"

When I click on the add page button, the above fields become prefaced (respectively):

"P#.Provider.P0.field_name"

"P#.Provider.P0.Hidden.field_name"

The # would represent the numbered page. So 'P1' after clicking 'ADD PAGE' button once, 'P2' after clicking 'ADD Page' button a second time.

I would like to now be able to hide all of the "P#.Provider.P0.Hidden" groups when I click on a 'HIDE' Button across all pages, no matter how many were created. The below script is using a hidden check box field to be able to turn on and off the hidden value using the same HIDE button. (just did it this way to test out various things)

     var oChkFld = this.getField("HiddenCheck"); 

     oChkFld.checkThisBox(0,!oChkFld.isBoxChecked(0));

     this.getField("P#.Provider.P0.Hidden").display = (oChkFld.value=="Off") ? display.hidden : display.visible;

What is the correct way to hide all of those fields across all pages when the # is an unknown?

Thanks!

Mike

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

I would use something like this:

for (var i=0; i<this.numFields; i++) {

    var f = this.getField(this.getNthFieldName(i));

    if (f==null) continue;

    if (/Hidden/.test(f.name)) f.display = display.hidden;

}

TOPICS
Acrobat SDK and JavaScript

Views

121

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 09, 2018 0
Most Valuable Participant ,
Aug 09, 2018

Copy link to clipboard

Copied

I would use something like this:

for (var i=0; i<this.numFields; i++) {

    var f = this.getField(this.getNthFieldName(i));

    if (f==null) continue;

    if (/Hidden/.test(f.name)) f.display = display.hidden;

}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 09, 2018 2
Adobe Community Professional ,
Aug 09, 2018

Copy link to clipboard

Copied

If the page number cannot be predicted reliably, then the thing to do is to search all the field names for those that contain the word "Hidden" or whatever other string uniquely identifies the fields.

// Use an array to collect the target fields

var aHiddenFlds = [];

for(var i=0;i<this.numFields;i++)

{

      var strFld = this.getNthFieldName(i);

      if(/Hidden/.test(strFld))

          aHiddenFlds.push(strFld);

}

Now you have a list of the needed fields

However, say the script is activated from a button (or other field) on the same page as the fields of interest, then the prefix can be acquired from the originating field.

if(/(P\d{1,2}.Provider)/.test(event.targetName))

{  

    var strPrefix = RegExp.$1;

   ... code for hiding fields ...

}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 09, 2018 2
mLomax LATEST
Community Beginner ,
Aug 09, 2018

Copy link to clipboard

Copied

Thanks to you both! I was able to get it to work. I appreciate the help very much!

Mike

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 09, 2018 0