Expand my Community achievements bar.

SOLVED

dynamic changes to decimal or text box fill color

Avatar

Level 3

I previously asked a question about how to programmatically change the background color of just the box of a checkbox object.  The code (which worked great) was as follows:

xfa.resolveNode("form1.page1.cb.ui.#checkButton.border.fill.color").value = "255,255,0";

I now need to do something similar for other types of objects.  In particular, I need to change the color of a decimal field and a text field.  I tried to find similar tags in the XML source that would give me some guidance.  I tried the following (based on my XML examination) for the decimal field, but it didn't work:

xfa.resolveNode("form1.page1.cb.ui.#numericEdit.border.fill.color").value = "255,255,0";

and

xfa.resolveNode("form1.page1.cb.#numericEdit.border.fill.color").value = "255,255,0";

Any insight into how I'd do the change for the decimal and text fields?

Thanks,
Emily

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi Emily,

You are on  the right track. Checking the XML source will highlight the syntax to access that property.

I have over time adapted the script to include gathering the SOM of the object and using that in the script. This way if the name of the object (or the name of the subform) is changed, then the script will still work. The only thing you need to change is the ui reference to match the object type.

The numericEdit will work on decimal objects and textEdit will work on text fields.

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

*/

Good luck,
Niall

View solution in original post

3 Replies

Avatar

Correct answer by
Level 10

Hi Emily,

You are on  the right track. Checking the XML source will highlight the syntax to access that property.

I have over time adapted the script to include gathering the SOM of the object and using that in the script. This way if the name of the object (or the name of the subform) is changed, then the script will still work. The only thing you need to change is the ui reference to match the object type.

The numericEdit will work on decimal objects and textEdit will work on text fields.

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

*/

Good luck,
Niall

Avatar

Level 3

Thanks, I think I'm heading in the right direction.

Although I'm finding that if I use .somExpression, then my JavaScript doesn't work.  It will only work if I remove the bracketed numbers from the .somExpression manually.  Any idea what I'm doing wrong?  Sound like using the SOM works for you.

Emily

Avatar

Level 10

Hi Emily,

I attached a sample to the original reply, so if you log onto the forum, you will be able to see the script in action. There are three examples in the form. You are looking for the second one (middle row).

I am not sure what you mean by removing the bracketed numbers from the .somExpression. The way that I do this is to assign the som expression to a variable and then use that in the xfa.resolveNode.

The only purpose of the som expression is to make it easier to reuse the object. When you copy it, you do not need to go back into the script and change it.

If you get the numericEdit and textEdit to work, then that would be enough.

Hope you get it working,

Niall