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

Mass Reset to Visibility of all Image Fields

New Here ,
May 15, 2018 May 15, 2018

Copy link to clipboard

Copied

Hi,

I am currently working on a large form, with a lot of images. Like, A LOT of images (200 give or take). In the form, these image's states of visibility are  changed by a different checkbox with a bit of javascript, and either the images are "hidden" or "hidden but printable". However, when I reset the form,  the images visibility's are not reset. This leaves the whole form so that the checkbox's states and the images visibility's aren't aligned anymore (IE a box will become unchecked after a reset, but because the code on the checkbox doesn't run, the image doesn't switch its state of visibility).

I am trying to figure out a fast way to reset all of the image visibility's to "hidden but printable" once the reset button is hit. I am not able to put every name of every image into an array, because of sheer volume (I have several different forms like this.)

Does anybody have any ideas?

(I have had a few ideas on how to do this but don't know how to execute them)

- Attach the same javascript to every image that tells it to reset its own visibility in the case of a form reset

- Setup an array on the reset button that automatically takes every image in the pdf (minus a certain few which I could write as exceptions in the script), and sets its visibility on mouseUp

-Somehow create a seperate layer on the form that is composed of all of my image fields, and change the visibility of the layer

Thanks so much for any help, this problem has been eating away at me for a while now!

TOPICS
Acrobat SDK and JavaScript , Windows

Views

491

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 , May 16, 2018 May 16, 2018

No, that's the entire point of it: To not have to specify the fields by name, except those (button) fields that you don't want to hide.

Here's the code:

var exceptions = ["Button1" ,"Button2", "Button5"];

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

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

    if (f==null) continue;

    if (f.type=="button" && f.buttonPosition!=position.textOnly && exceptions.indexOf(f.name)==-1) {

        f.display = display.hidden;      

    }

}

Votes

Translate

Translate
Community Expert ,
May 15, 2018 May 15, 2018

Copy link to clipboard

Copied

The second approach is the best one, only you don't need an array for the

fields to process, only for those to skip.

You can use a for-loop and the getNthFieldName method to iterate over all

the fields in the file, hiding those that are: buttons, with images, and

not in the exceptions array.

I will be able to send some sample code later on.

On Wed, May 16, 2018, 07:49 ChristopherMountain <forums_noreply@adobe.com>

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
New Here ,
May 16, 2018 May 16, 2018

Copy link to clipboard

Copied

Thanks so much!

I am a bit of a javascripting novice so I am looking forward to the sample code, but thanks for the suggestion - this sounds like it could work really well. My only question is: will I have to input all of the names of fields I am not using into the script? There is a similar amount of checkbox fields as there are to images, and it will probably be as difficult to compile all of the field exceptions as it would to write all of the image fields.

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 ,
May 16, 2018 May 16, 2018

Copy link to clipboard

Copied

No, that's the entire point of it: To not have to specify the fields by name, except those (button) fields that you don't want to hide.

Here's the code:

var exceptions = ["Button1" ,"Button2", "Button5"];

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

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

    if (f==null) continue;

    if (f.type=="button" && f.buttonPosition!=position.textOnly && exceptions.indexOf(f.name)==-1) {

        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
New Here ,
May 17, 2018 May 17, 2018

Copy link to clipboard

Copied

LATEST

This works perfectly!

Thanks a ton, this completely saved my project.

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