Expand my Community achievements bar.

Table cell color change

Avatar

Level 3

I have a table with multiple columns.

And a button that adds a new row on click.

I want to change the fillcolor of one cell if that cell is empty.

Is this posible?

I know how to do it on normal fields, but not with a table

if ((xfa.resolveNode("name").rawValue == null) || (xfa.resolveNode("name").rawValue == "")) {


xfa.resolveNode("name.ui.#textEdit.border.fill.color").value = "255,0,0";


}


else


xfa.resolveNode("name.ui.#textEdit.border.fill.color").value = "255,255,255";

Can anyone help me to create a script for changing the color of a single cell when empty?

5 Replies

Avatar

Level 3

I've changed the script according to an other forum.

But it doesn't work

Can some one take a look at it?

var vName = this.somExpression;

var fieldObj = xfa.resolveNode(vName + ".ui.#textEdit.border.fill.color");


if (this.rawValue == null) || (this.rawValue == "")) {

fieldObj.value = "255,0,0";

}

else

fieldObj.value = "255,255,255";

I think i miss some double quotes

But Javascript wil see the double quotes as a string, not as text

Any help please

Avatar

Level 10

Hi,

That will work if the object you are changing is a textfield. if it is another type of object you will need to swap out the #textEdit to match the object type.

/* Check the type of object and change the .ui reference:

     Date field =      #dateTimeEdit 

     Dropdown =      #choiceList 

     Checkbox =      #checkButton 

     Text field =      #textEdit 

     Numeric field =     #numericEdit


*/

See the sample here: https://acrobat.com/#d=xHziYOr8zapKWtuVhWUk0w

Good luck,

Niall

PS:

Also you will need to give the object a background colour at design time. Set the initial colour to white. The script will then change the colour. If the object doesn't have a background, then the script will fail. You can set the initial background in Object > Field > Appearance > Custom...

Avatar

Level 3

Well, it is a text field

So it should work, but it doesn't

Does this work on a dynamic table?

I suspect that there are double quotes missing behind ( and before )???

var fieldObj = xfa.resolveNode(vName + ".ui.#textEdit.border.fill.color");

vs

xfa.resolveNode("formulier1.#subform[0].top.PostcodePlaats.ui.#textEdit.border.fill.color").value = "255,255,255";

Avatar

Level 10

Hi,

I have used this type of script a lot and it works OK.

Here is the full script that is included in the previous example:

var vName = this.somExpression;

var fieldObj = xfa.resolveNode(vName + ".ui.#textEdit.border.fill.color");


fieldObj.value = "255,255,255"; // white

/* Check the type of object and change the .ui reference:

     Date field =      #dateTimeEdit 

     Dropdown =      #choiceList 

     Checkbox =      #checkButton 

     Text field =      #textEdit 

     Numeric field =     #numericEdit

*/ 

Check that the object has a white background to start with and that the form is saved as dynamic.

Assigning the object's SOM to the vName variable means that you can use it for any object (including a cell in a dynamic table) and it will work.

I have set up a function to deal with different objects, but that is just following the same process as above. https://acrobat.com/#d=XGj9UEk4lSbDSoArnQU8dQ

If you open the previous example in LC Designer it may show where the problem is.

Niall

Avatar

Level 3

Hi,

It works!!!

I made a stupid copy/paste mistake

Thank you for your help