rjohns Posted June 17, 2015 Share Posted June 17, 2015 I'd like to change the text color for all of the text in a specific text frame based on the value of a field. For example, if the field value contains the word "color," change the text color for all the text in the text frame named "Address" to Pantone 424 C. I've tried searching the existing posts, but I haven't found one addressing this specific topic. The best I've come up with so far is: if (Field("SizeColor").indexOf("color") > -1) { return FindTextFrame("Address").content("<color name=\"PANTONE 424 C\">") } return ""; Any help would be much appreciated – thanks! Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted June 17, 2015 Share Posted June 17, 2015 In OnRecordStart, you should be able to do this: if (Field("SizeColor").indexOf("color") > -1) FindTextFrame("Address").content = '<span color="PANTONE 424 C">' + FindTextFrame("Address").content; Or, you can create a regular Text rule like so: if (Field("SizeColor").indexOf("color") > -1) return '<span color="PANTONE 424 C">'; //else return ""; And, with the Text Editor dialog, insert the name of that rule as a variable at the start of the text for the frame in question. Quote Link to comment Share on other sites More sharing options...
step Posted June 17, 2015 Share Posted June 17, 2015 I'm not quite sure what you're trying to achieve here, but if you want to change all of the text in the frame "Address" to "PANTONE 424 C" when the field "SizeColor" contains the word "color" somewhere in it, you can do this: OnRecordStart var field = Field("SizeColor"); var color = "PANTONE 424 C"; if (field.match(/color/)) { FindTextFrame("Address").content = '<span color="' + color +'">' + FindTextFrame("Address").content + '</span>'; } The above is essentially wrapping the entire contents of the frame with span tags. I should note: any text in that frame that previously had span tags applied to it will remain the color of their previous span tags by nature of how span tags work. Meaning, if you have JavaScript rules that are returning (span) tagged text in a color other than Pantone 424 (for example: blue), that text will remain blue. If that's the case you'd want to do a find and replace on all of your color tags in the "address" text frame and update them to Pantone 424. But that's a little more convoluted: var field = Field("SizeColor"); var color = "PANTONE 424 C"; if (field.match(/color/)) { var text = FindTextFrame("Address").content; text = text.replace(/<variable name="([^"]*)">/g, function(s,p){return FieldOrRule(p);}); text = text.replace(/(<color name=")[^"]*(">)|(<span(??!color).)*color=")[^"]*(">)/g, '$1' + color + '$2' ); FindTextFrame("Address").content = text; } Quote Link to comment Share on other sites More sharing options...
rjohns Posted June 18, 2015 Author Share Posted June 18, 2015 Thanks for your help, Dan and Ste! I ended up using the text rule –*it works beautifully. It never crossed my mind to handle it that way. Thanks again! Quote Link to comment Share on other sites More sharing options...
JCrocker Posted December 2, 2015 Share Posted December 2, 2015 This is exactly what I'm attempting to do. I'm using the text rule and have inserted it into the text editor dialog box but it is returning the literal text of the rule. I'm missing one small step I believe here. I've created four new colors named, Spot Red, Spot Green, Spot Blue, and Spot gray. Here's what I've got so far: if (Field("Background").indexOf("BLUE") > -1) return '<span color="Spot Blue">'; if (Field("Background").indexOf("GREEN") > -1) return '<span color="Spot Green">'; if (Field("Background").indexOf("RED") > -1) return '<span color="Spot Red">'; if (Field("Background").indexOf("GRAY") > -1) return '<span color="Spot Gray">'; //else return ""; Its functioning but its returning the literal text in the text box - for example: <span color="Spot Gray"> or <span color="Spot Red"> What am I missing here guys? Thanks in advance. Quote Link to comment Share on other sites More sharing options...
dreimer Posted December 2, 2015 Share Posted December 2, 2015 Do you have "Treat returned strings as tagged text" checked in your rule? Quote Link to comment Share on other sites More sharing options...
JCrocker Posted December 2, 2015 Share Posted December 2, 2015 (edited) Nope, that's it!! Thank you very much dreimer!! I apologize for my inexperience. Edited December 2, 2015 by JCrocker 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.