Skip to main content
Inspiring
August 1, 2018
解決済み

Change borderColor fields in Array

  • August 1, 2018
  • 返信数 7.
  • 1661 ビュー

I would like to change the border color of all of the fields in a 60+ array of fields, dependent upon whether a button is hidden, without having to set each field border color one-by-one. Here is an example of how I have this set up, which is not working. How can I do this?

var btn = this.getField("btn.ABC");

var highlight = new Array()

    highlight[0] = "chk.BP"

    highlight[1] = "txt.CD.A.Line.01.b"

    highlight[2] = "num.CD.BPAC.A.01"

    highlight[3] = "num.CD.BPBC.A.01"

    highlight[4] = "txt.CD.A.02"

    highlight[5] = "num.CD.BPAC.A.02"

if(btn.hidden == true){highlight.borderColor = color.white}else {highlight.borderColor = color.black}

このトピックへの返信は締め切られました。
解決に役立った回答 gkaiseril

That means one of your field names is incorrect.

On 2 August 2018 at 01:07, ddunn@davidsdunn.com <forums_noreply@adobe.com>


Within a script one can tell if the "getField" failed by checking to see if the returned variable of object the method is a null value or not. Since your array cells consist of the field object for each field, just use the cell's contents to access the field's value.

var btn = getField("btn.Defaults.Loan");

var highlight = new Array(

"chk.BP"

"txt.CD.A.Line.01.b"

"num.CD.BPAC.A.01",

"num.CD.BPBC.A.01",

"txt.CD.A.02"'

"num.CD.BPAC.A.02",

"num.CD.BPBC.A.02",

"txt.CD.A.03",

"num.CD.BPAC.A.03",

"num.CD.BPBC.A.03",

"txt.CD.A.04”

)

//this continues, naming 63 fields in this manner

for (var i in highlight) {

var f = this.getField(highlight);

if(f == null) {

  console.show();

  app.alert("Error accessing field " + highlight, 1, 0, "Field Access Error");

} // end if field object null;

  if (btn.hidden == true) {

  f.strokeColor = color.cyan;

} else {

  f.strokeColor = ["RGB", 1, .8, .05];

  f.fillColor = ["RGB", .92, .92, .92];

} // end if;

} // end for loop;

返信数 7

try67
Community Expert
Community Expert
August 1, 2018

Several issues there:

1. That's not how arrays work. You need to use a for-loop and iterate over each item in it.

2. You can't use the name to access the field, you have to do it via the getField method.

3. Fields don't have a borderColor property. The name of this property is strokeColor.

So use this code:

for (var i in highlight) {

    var f = this.getField(highlight);

    if (btn.hidden == true) { f.strokeColor = color.white; } else { f.strokeColor = color.black; }

}

ODuinn作成者
Inspiring
August 1, 2018

Thank you very much.

I follow what you’re telling me, however, I’m getting an “f is null” error message.

Am I still not identifying my fields correctly? Here’s what I’ve done:

var btn = getField("btn.Defaults.Loan");

var highlight = new Array();

highlight[0] = this.getField("chk.BP");

highlight[1] = this.getField("txt.CD.A.Line.01.b");

highlight[2] = this.getField("num.CD.BPAC.A.01");

highlight[3] = this.getField("num.CD.BPBC.A.01");

highlight[4] = this.getField("txt.CD.A.02");

highlight[5] = this.getField("num.CD.BPAC.A.02");

highlight[6] = this.getField("num.CD.BPBC.A.02");

highlight[7] = this.getField("txt.CD.A.03");

highlight[8] = this.getField("num.CD.BPAC.A.03");

highlight[9] = this.getField("num.CD.BPBC.A.03");

highlight[10] = this.getField("txt.CD.A.04”);

//this continues, naming 63 fields in this manner

for (var i in highlight) {

var f = this.getField(highlight);

if (btn.hidden == true) { f.strokeColor = color.cyan;} else { f.strokeColor = ["RGB", 1, .8, .05]; f.fillColor = ["RGB", .92, .92, .92];}

}

David

try67
Community Expert
Community Expert
August 1, 2018

That means one of your field names is incorrect.

On 2 August 2018 at 01:07, ddunn@davidsdunn.com <forums_noreply@adobe.com>