Expand my Community achievements bar.

SOLVED

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

Avatar

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

Avatar

Correct answer by
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

Avatar

Correct answer by
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