mddarfus Posted December 3, 2012 Share Posted December 3, 2012 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>'; } Quote Link to comment Share on other sites More sharing options...
step Posted December 3, 2012 Share Posted December 3, 2012 (edited) 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 December 4, 2012 by step Quote Link to comment Share on other sites More sharing options...
mddarfus Posted December 4, 2012 Author Share Posted December 4, 2012 Thank you so much! Both of those worked just the way I needed. I really appreciate your time and expertise. Quote Link to comment Share on other sites More sharing options...
mddarfus Posted December 4, 2012 Author Share Posted December 4, 2012 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. Quote Link to comment Share on other sites More sharing options...
step Posted December 4, 2012 Share Posted December 4, 2012 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. Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted December 4, 2012 Share Posted December 4, 2012 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. Quote Link to comment Share on other sites More sharing options...
step Posted December 4, 2012 Share Posted December 4, 2012 That's not true; color names are case-insensitive in FusionPro. Well I'll be Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.