Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events
SOLVED

dynamic color change of bottom border only

Avatar

Level 3

I have a text box in a form that only has the bottom border shown.  That box gets activated and deactivated programmatically (using a function) depending on whether some other checkboxes are checked.  When the text box is active, it is set to access='open' and I want the bottom border to change from gray to black.

I have what I believe is the correct function code for generally changing the color of a border, shown below:

function

ULineTBoxOn(MySubformNum,MyFieldRef){

eval(MyFieldRef

+ ".access = 'open';");

eval("xfa.resolveNode('form1.#subform["

+ MySubformNum + "]." + MyFieldRef + ".ui.#textEdit.border.edge.color').value = '" + BlackCode.value + "';");

}

But this does not do anything to my particular text box.  I did a text where I enabled all of the borders of my text box and then ran the above function on that text box, and it changed the color only of the top border.

I see in the text box's XML code that the properties for each border edge are set one at a time, with the bottom edge being third, as shown below:

<field name="Docket_Year" y="90.17mm" x="147.3198mm" w="13.4239mm" h="6.35mm" access="readOnly">

<ui>

<textEdit hScrollPolicy="off">

<border>

<edge presence="hidden"/>

<edge presence="hidden"/>

<edge/>

<edge presence="hidden"/>

<?templateDesigner StyleID aped1?></border>

<margin/>

</textEdit>

<picture>99</picture>

</ui>

What seems to be happening when I run my function shown above is that I am only changing the color of the FIRST edge referenced in the XML, which is the top (?).  Or something like that.  How would I change the color of the BOTTOM edge only?

Thanks,
Emily

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi Emily,

Once you have assigned your variable and passed it to your function - you can resolve it inside the function and then the following works here:

MyResFieldRef.ui.oneOfChild.border.getElement("edge",2).color.value = fieldFocus.value;

Your script is accessing "#textEdit" - try "oneOfChild".

Modified example working on text field and numeric field.

Hope you get it working,

Niall

View solution in original post

10 Replies

Avatar

Level 10

Hi Emily,

The script to access the colour of a single edge of an object is:

this.ui.oneOfChild.border.getElement("edge",2).color.value = "255,153,0"; //orange tinge

See third row in this sample.

Good luck,

Niall

Avatar

Level 3

Thanks,

I've tried the following.  I think I'm close, but haven't gotten any of these to work yet.

eval("xfa.resolveNode('form1.#subform["

+

MySubformNum + "]." + MyFieldRef + ".ui.oneOfChild.border.getElement('edge',3).edge.color').value = '" + BlackCode.value + "';");

eval("xfa.resolveNode('form1.#subform["

+ MySubformNum + "]." + MyFieldRef + ".ui.#textEdit.border.getElement('edge',XXX).edge.color').value = '" + BlackCode.value + "';");

eval("xfa.resolveNode('form1.#subform[" + MySubformNum + "]." + MyFieldRef + ".ui.#textEdit.oneOfChild.border.getElement('edge',XXX).edge.color').value = '" + BlackCode.value + "';");

I've tried each of these for XXX = 1, 2, 3, and 4, but no luck.

Any suggestions to push me over the edge?

Emily

Avatar

Level 10

... edge ;-)

I think that you may be bitting off too much (initially at least) I would row back first and get it working for an object. Then I would start building in the complexity of referencing specific subform objects.

It looks like the subform is not named. While they may be several subforms with the same name [*]; I would be inclined to name them at least. Also it might be worth inserting a few console.println into the function, so that you can try and catch if variables like MySubformNum and MyFieldRef are coming in correctly into the function.

To a certain degree that is why I get the SOM of the object and put this into a variable. This would be before you call the function. You can then pass that variable through to the function:

Parallels Desktop.png

Something like this:

var MyFieldRef = this.somExpression;

MyScriptObject.MyFunction(MyFieldRef);

Then the function would include:

MyFunction(MyFieldRef)

{

     ...

     xfa.resolveNode(MyFieldRef + ".ui.oneOfChild.border.getElement('edge',3).edge.color").value = BlackCode.value;

     ...

}

I think you may have an extra ) in your script and I am not sure why you are evaluating the script as opposed to just running it. I haven't tried the above, but it should work.

Good luck,

Niall

Avatar

Level 3

I got it to work on a single element.  The code (for an element named 'Docket_Year' was as follows:

xfa.resolveNode(Docket_Year.somExpression + ".ui.#textEdit.border.getElement('edge',2).color").value = BlackCode.value;

where BlackCode.value is '0,0,0'.

I also got it to work in a function.  I can call it successfully for an element form1.#subform[4].Docket_Year as follows:

FormScripts.ULineTBoxOn(4

,'Docket_Year');

function

ULineTBoxOn(MySubformNum,MyFieldRef){

xfa.resolveNode("form1.#subform["

+ MySubformNum + "]." + MyFieldRef + ".ui.#textEdit.border.getElement('edge',2).color").value = BlackCode.value;

}

However, after much trying, I have never been able to get somExpression to work when I use it with a function.  I tried the following:

FormScripts.ULineTBoxOn(Docket_Year.somExpression);

function

ULineTBoxOnSOM(MyFieldRef){

xfa.resolveNode(MyFieldRef).ui.#textEdit.border.getElement('edge'

,2).color.value = BlackCode.value;

}

I also tried

function

ULineTBoxOnSOM(MyFieldRef){

xfa.resolveNode(MyFieldRef + ".ui.#textEdit.border.getElement('edge',2).color").value = BlackCode.value;

}

I've also tried the somExpression approach with other types of unrelated code, and they did not work.  It's like the somExpression is out of scope for my script object, or something like that.  It doesn't seem to know what it is.  I would REALLY love to figure out how to solve this.  It would very much simplify a lot of things I'm doing.  I'll probably post a separate question about that, but if you happen to spot any obvious things that I'm screwing up while trying to use the somExpression, please let me know.

Thanks again!  I would not have been anywhere near the correct answer without your assistance.

Emily

Avatar

Level 3

Also, ignore the fact that my function names don't match in the previous post.  They were

all the same name (ULineTBoxOnSOM) when I tested them, so that isn't the problem.

Avatar

Level 10

Hi,

I went back to one of my forms and abstracted a field, the script object and some global variables.

Here is a working example.

This is how I am resolving the name of the object and then passing that through to the function:

var vName = this.somExpression;

var fieldObj = xfa.resolveNode(vName);

colourControls.fieldGetsFocus(fieldObj);

I hope that helps,
Niall

Avatar

Level 3

I've gotten the following to work, so I know that I can pass a somExpression value to a function:

FormScripts.ULineTBoxOnSOM(Docket_Year.somExpression);

function

ULineTBoxOnSOM(MyFieldRef){

     var MyResFieldRef = xfa.resolveNode(MyFieldRef);

     MyResFieldRef.access

= 'open';

}

But I can't get that resolveNode value to work with some more complicated statements.

For instance, I'm trying to run the following:

FormScripts.ULineTBoxOnSOM(Docket_Year.somExpression);

function

ULineTBoxOnSOM(MyFieldRef){

     var MyResFieldRef = xfa.resolveNode(MyFieldRef);

     xfa.resolveNode(MyResFieldRef + ".ui.#textEdit.border.getElement('edge',2).color").value = BlackCode.value;

}

I've tried many variations on this:

     xfa.resolveNode("MyResFieldRef.ui.#textEdit.border.getElement('edge',2).color").value = BlackCode.value;

     xfa.resolveNode(MyResFieldRef.ui.#textEdit.border.getElement('edge',2).color).value = BlackCode.value;

     MyResFieldRef.ui.#textEdit.border.getElement('edge'

,2).color.value = BlackCode.value;

I have gotten this to work as follows:


,'Docket_Year');

FormScripts.ULineTBoxOn(4




ULineTBoxOn(MySubformNum,MyFieldRef){
+ MySubformNum + "]." + MyFieldRef

xfa.resolveNode("form1.#subform["

+ ".ui.#textEdit.border.getElement('edge',2).color").value = BlackCode.value;

}

I have also tried doing the somExpression resolveNode in the script from which I'm calling the

function, and assigning it to a variable (as Naill suggested).  That didn't work here (although it

did work with my .access = 'open" example.  I'd like to stuff that step into the function though,

so I can cut down on the size of my script.  It appears that my problem is in my syntax using the

someExpression variable, and not on passing the variable to a function.  Any insight?

Thanks!

Emily

function

Avatar

Correct answer by
Level 10

Hi Emily,

Once you have assigned your variable and passed it to your function - you can resolve it inside the function and then the following works here:

MyResFieldRef.ui.oneOfChild.border.getElement("edge",2).color.value = fieldFocus.value;

Your script is accessing "#textEdit" - try "oneOfChild".

Modified example working on text field and numeric field.

Hope you get it working,

Niall

Avatar

Level 3

Yes!  I have a perfectly working function.  I even simlified it a bit.  For those of you possibly reading this to figure out how to do this, see below:

FormScripts.ULineTBoxOn(Docket_Year);

where 'Docket_Year' is just the name of a text field.

function

ULineTBoxOn(MyField){

var MyResField = xfa.resolveNode(MyField.somExpression);

MyResField.ui.oneOfChild.border.getElement('edge'

,2).color.value = BlackCode.value;

}

Thanks again,

Emily

Avatar

Level 10

Glad you got it working - good job. Also nice to see some continuous improvement!!

Good luck,

Niall