Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

Script to change text color set by user using the Form Field Text Properties Bar

DKinsley
Level 9
Level 9

Is there a way to script to change all of the text in a textField back to text color black ("0,0,0") if a user has changed the text color using the Form Field Text Properties Bar? It looks like that is done on a separate layer?

I tried this and it does not work:

Subform1.UpperSection.font.fill.color.value = "0,0,0";

and I tried:

Subform1.UpperSection.font.color = "0,0,0";

1 Accepted Solution
_Bruce_Robertson
Correct answer by
Level 10
Level 10

Hi,

You will have to go though each property of the rich text value looking for a textColor property, so something like this JavaScript in the exit event;

var spans = util.xmlToSpans(this.value.exData["##xHTML"].saveXML());

for (var i = 0; i < spans.length; i++)

{

    if (spans[i].textColor && !color.equal(spans[i].textColor, color.black))

    {

        spans[i].textColor = color.black;

    }

}

var xHTML = util.spansToXML(spans);

this.value.exData.loadXML(xHTML, false, true);

Using util.xmlToSpans() will lose some other formatting, as it only supports a subset of what is available.  If that is a problem then you can use E4X or some other XML handling code.

Bruce

View solution in original post

2 Replies
_Bruce_Robertson
Correct answer by
Level 10
Level 10

Hi,

You will have to go though each property of the rich text value looking for a textColor property, so something like this JavaScript in the exit event;

var spans = util.xmlToSpans(this.value.exData["##xHTML"].saveXML());

for (var i = 0; i < spans.length; i++)

{

    if (spans[i].textColor && !color.equal(spans[i].textColor, color.black))

    {

        spans[i].textColor = color.black;

    }

}

var xHTML = util.spansToXML(spans);

this.value.exData.loadXML(xHTML, false, true);

Using util.xmlToSpans() will lose some other formatting, as it only supports a subset of what is available.  If that is a problem then you can use E4X or some other XML handling code.

Bruce

View solution in original post