Field handling

Engaged ,
Nov 01, 2018 Nov 01, 2018

Copy link to clipboard

Copied

I have the following code (which probably isn't written the most efficient)....

// TURN ON ALL EYE ICONS FOR THIS PAGE

if (this.getField("groundState") != null){

var getState = this.getField("groundState");

var theFieldsPage = getState.page;

if (getState != null) {

// Look through the fields page numbers

for (var z = 0; z < theFieldsPage.length; z++) {

// Find the field on the right page

if (theFieldsPage == this.pageNum) {

// Only change the display of the field on this page

getField("groundState." + z).display = display.hidden;

}}}

}

// TURN ON ALL EYE ICONS FOR THIS PAGE

if (this.getField("021state") != null){

var getState = this.getField("021state");

var theFieldsPage = getState.page;

if (getState != null) {

// Look through the fields page numbers

for (var z = 0; z < theFieldsPage.length; z++) {

// Find the field on the right page

if (theFieldsPage == this.pageNum) {

// Only change the display of the field on this page

getField("021state." + z).display = display.hidden;

}}}

}

// TURN ON ALL EYE ICONS FOR THIS PAGE

if (this.getField("032state") != null){

var getState = this.getField("032state");

var theFieldsPage = getState.page;

if (getState != null) {

// Look through the fields page numbers

for (var z = 0; z < theFieldsPage.length; z++) {

// Find the field on the right page

if (theFieldsPage == this.pageNum) {

// Only change the display of the field on this page

getField("032state." + z).display = display.hidden;

}}}

}

It is applied to a button. If the field groundState exist and 032state exists.... how do I get it to hide those fields?

So 021state doesn't exist in this particular document... I thought if I put it != null that would work. Currently it only hides the field groundState and doesn't hide the 032state field as it should.

Any suggestions would be most appreciated! Feel free to make suggestions for optimizing the script as well

Thanks in advance!

TOPICS
Acrobat SDK and JavaScript, Macintosh

Views

203

Likes

translate

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
Adobe Community Professional ,
Nov 01, 2018 Nov 01, 2018

Copy link to clipboard

Copied

How many fields with the name "032state" are in the document?

Likes

translate

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
Engaged ,
Nov 01, 2018 Nov 01, 2018

Copy link to clipboard

Copied

It varies. Could be 0.... could be up to 8.

Likes

translate

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
Adobe Community Professional ,
Nov 01, 2018 Nov 01, 2018

Copy link to clipboard

Copied

When there are only one field with the name the property page will not return a array.

Likes

translate

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
Engaged ,
Nov 01, 2018 Nov 01, 2018

Copy link to clipboard

Copied

OH I see! Any suggestions for how to address that?

Likes

translate

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
Adobe Community Professional ,
Nov 01, 2018 Nov 01, 2018

Copy link to clipboard

Copied

Compare the property page with the current page.

Likes

translate

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
Engaged ,
Nov 01, 2018 Nov 01, 2018

Copy link to clipboard

Copied

I thought that is what I was doing with this line?...

if (theFieldsPage == this.pageNum) {

Likes

translate

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
Adobe Community Professional ,
Nov 01, 2018 Nov 01, 2018

Copy link to clipboard

Copied

Remove

Likes

translate

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
Engaged ,
Nov 01, 2018 Nov 01, 2018

Copy link to clipboard

Copied

Ok so when I do that it doesn't function properly.... here is what my updated script looks like:

// TURN ON ALL EYE ICONS FOR THIS PAGE

if (this.getField("groundState") != null){

var getState = this.getField("groundState");

var theFieldsPage = getState.page;

// Find the field on the right page

if (theFieldsPage == this.pageNum) {

// Only change the display of the field on this page

getField("groundState").display = display.visible;

}}

// TURN ON ALL EYE ICONS FOR THIS PAGE

if (this.getField("021state") != null){

var getState = this.getField("021state");

var theFieldsPage = getState.page;

// Find the field on the right page

if (theFieldsPage == this.pageNum) {

// Only change the display of the field on this page

getField("021state").display = display.visible;

}}

// TURN ON ALL EYE ICONS FOR THIS PAGE

if (this.getField("032state") != null){

var getState = this.getField("032state");

var theFieldsPage = getState.page;

// Find the field on the right page

if (theFieldsPage == this.pageNum) {

// Only change the display of the field on this page

getField("032state").display = display.visible;

}}

It doesn't turn on the fields because if there are multiple instances they are  032state#0 032state#1

So it doesn't turn any of them on. That is why I had the script originally written with this in it:

// Look through the fields page numbers

for (var z = 0; z < theFieldsPage.length; z++) {

// Find the field on the right page

if (theFieldsPage == this.pageNum) {

// Only change the display of the field on this page

getField("032state." + z).display = display.visible;

}}

Thank you for sticking with me on this! I appreciate it!

Likes

translate

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
Adobe Community Professional ,
Nov 01, 2018 Nov 01, 2018

Copy link to clipboard

Copied

Don't delete the z loop.

Likes

translate

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