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

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

Community Beginner ,
Aug 09, 2018 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

TOPICS
Acrobat SDK and JavaScript

Views

410

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
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 09, 2018 Aug 09, 2018

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;

}

Votes

Translate

Translate
Community Expert ,
Aug 09, 2018 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;

}

Votes

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
community guidelines
Community Expert ,
Aug 09, 2018 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 ...

}

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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
community guidelines
Community Beginner ,
Aug 09, 2018 Aug 09, 2018

Copy link to clipboard

Copied

LATEST

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

Mike

Votes

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
community guidelines