Jump to content

Set color for two complete text boxes with one "OnRecordStart" Rule


mddarfus

Recommended Posts

I have an "OnRecordStart" rule written (based on one found here on the forum) that I'm trying to use to set the text color for two separate text boxes. It works correctly for the first box (called "Top Box" in the rule), but it doesn't affect the color of the text in the second box (called "Bottom Box" in the rule).

 

I'm sure I'm missing something simple in my javascript, but I can't figure it out. Any help would be greatly appreciated as always.

 

The rule I've written is copied below:

 

 

var TopTextFrame = FindTextFrame("Top Block");

{

if (Field("Backside Text Color") == "FiveStarGreen")

return TopTextFrame.content = '<span color="FiveStarGreen">' +

TopTextFrame.content + '</span>';

}

{

if (Field("Backside Text Color") == "FiveStarGray")

return TopTextFrame.content = '<span color="FiveStarGray">' +

TopTextFrame.content + '</span>';

}

{

if (Field("Backside Text Color") == "Black")

return TopTextFrame.content = '<span color="Black">' +

TopTextFrame.content + '</span>';

}

{

if (Field("Backside Text Color") == "White")

return TopTextFrame.content = '<span color="White">' +

TopTextFrame.content + '</span>';

}

var BottomTextFrame = FindTextFrame("Bottom Block");

{

if (Field("Backside Text Color") == "FiveStarGreen")

return BottomTextFrame.content = '<span color="FiveStarGreen">' +

BottomTextFrame.content + '</span>';

}

{

if (Field("Backside Text Color") == "FiveStarGray")

return BottomTextFrame.content = '<span color="FiveStarGray">' +

BottomTextFrame.content + '</span>';

}

{

if (Field("Backside Text Color") == "Black")

return BottomTextFrame.content = '<span color="Black">' +

BottomTextFrame.content + '</span>';

}

{

if (Field("Backside Text Color") == "White")

return BottomTextFrame.content = '<span color="White">' +

BottomTextFrame.content + '</span>';

}

Link to comment
Share on other sites

The reason your code doesn't work is because you have if statements that are conditional upon the same thing happening and the JavaScript executes the first one (the top one).

 

var TopTextFrame = FindTextFrame("Top Block");
{
[color="Red"]if (Field("Backside Text Color") == "FiveStarGreen")[/color]
return TopTextFrame.content = '<span color="FiveStarGreen">' + 
TopTextFrame.content + '</span>';
}
{
if (Field("Backside Text Color") == "FiveStarGray")
return TopTextFrame.content = '<span color="FiveStarGray">' + 
TopTextFrame.content + '</span>';
}
{
if (Field("Backside Text Color") == "Black")
return TopTextFrame.content = '<span color="Black">' + 
TopTextFrame.content + '</span>';
}
{
if (Field("Backside Text Color") == "White")
return TopTextFrame.content = '<span color="White">' + 
TopTextFrame.content + '</span>';
}
var BottomTextFrame = FindTextFrame("Bottom Block");
{
[color="red"]if (Field("Backside Text Color") == "FiveStarGreen")[/color]
return BottomTextFrame.content = '<span color="FiveStarGreen">' + 
BottomTextFrame.content + '</span>';
}
{
if (Field("Backside Text Color") == "FiveStarGray")
return BottomTextFrame.content = '<span color="FiveStarGray">' + 
BottomTextFrame.content + '</span>';
}
{
if (Field("Backside Text Color") == "Black")
return BottomTextFrame.content = '<span color="Black">' + 
BottomTextFrame.content + '</span>';
}
{
if (Field("Backside Text Color") == "White")
return BottomTextFrame.content = '<span color="White">' + 
BottomTextFrame.content + '</span>';
}

 

You would need to rework the code so that both results happen at the same time when that condition is met. (Also, OnRecordStart callback rules don't actually return anything so you don't need to write a "return" line in your code)

 

var TopTextFrame = FindTextFrame("Top Block");
var BottomTextFrame = FindTextFrame("Bottom Block");

if (Field("Backside Text Color") == "FiveStarGreen") {
   TopTextFrame.content = '<span color="FiveStarGreen">' + TopTextFrame.content + '</span>';
   BottomTextFrame.content = '<span color="FiveStarGreen">' + BottomTextFrame.content + '</span>';
}
else if (Field("Backside Text Color") == "FiveStarGray") {
   TopTextFrame.content = '<span color="FiveStarGray">' + TopTextFrame.content + '</span>';
   BottomTextFrame.content = '<span color="FiveStarGray">' + BottomTextFrame.content + '</span>';
}
else if (Field("Backside Text Color") == "Black") {
   TopTextFrame.content = '<span color="Black">' + TopTextFrame.content + '</span>';
   BottomTextFrame.content = '<span color="Black">' + BottomTextFrame.content + '</span>';
}
else if (Field("Backside Text Color") == "White") {
   TopTextFrame.content = '<span color="White">' + TopTextFrame.content + '</span>';
   BottomTextFrame.content = '<span color="White">' + BottomTextFrame.content + '</span>';
}

 

Or you could simplify things a little bit and write it like this:

 

FindTextFrame("Top Block").content = '<span color="' + Field("Backside Text Color") + '">' + FindTextFrame("Top Block").content + '</span>';
FindTextFrame("Bottom Block").content = '<span color="' + Field("Backside Text Color") + '">' + FindTextFrame("Bottom Block").content + '</span>';

Edited by step
Link to comment
Share on other sites

The only trouble I've run into is that the rules will only work with colors that were originally imported from my InDesign file into the FusionPro PDF.

 

If I try to add a new color using the FusionPro–> Advanced–>Color... menu, giving the new color a name like Blue or Red and assigning CMYK values, and then adding those same color names to the data field "Backside Text Color" on a few records.... the color does not show up when I preview those records. Is that a FusionPro 8.2 glitch, or am I doing something wrong? I'm guessing the latter.

Link to comment
Share on other sites

It sounds like what you're attempting to do should work. Make sure that "Blue" and "Red" aren't already defined in the Advanced>Color library and make sure they are named exactly as they appear in your data. If one's capitalized and one isn't the FP won't be able to find that color in the library. Also check to make sure you didn't inadvertently add a trailing space at the end of the color name in the data file.
Link to comment
Share on other sites

If one's capitalized and one isn't the FP won't be able to find that color in the library.

That's not true; color names are case-insensitive in FusionPro.

Also check to make sure you didn't inadvertently add a trailing space at the end of the color name in the data file.

That's a possibility. That could be solved with a call to the Trim function, like so in your example:

FindTextFrame("Top Block").content = '<span color="' + [color=SeaGreen]Trim[/color](Field("Backside Text Color")) + '">' + FindTextFrame("Top Block").content + '</span>';
FindTextFrame("Bottom Block").content = '<span color="' + [color=SeaGreen]Trim[/color](Field("Backside Text Color")) + '">' + FindTextFrame("Bottom Block").content + '</span>';

Of course, the first step in any troubleshooting is to do a full composition (not a Preview), and click View Log.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...