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

Field handling

Engaged ,
Nov 01, 2018 Nov 01, 2018

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

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

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

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

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

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

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

OH I see! Any suggestions for how to address 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
Community Expert ,
Nov 01, 2018 Nov 01, 2018

Compare the property page with the current page.

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

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

if (theFieldsPage == this.pageNum) {

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

Remove

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

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!

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

Don't delete the z loop.

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