stephsal Posted August 31, 2016 Share Posted August 31, 2016 I've been using simple rules for internal client templates and so far this has been straightforward but right now, I'm at a loss to what to for a more complex rule. Disclaimer is I'm not a developer and more of a HTML/CSS person so I've been going in blind for a lot of the more complex (to me) JavaScript (I have been using the W3 School site to try to learn it) - So please bear with me. Currently I'm working on a project on Fusion pro that requires the street address and city of one of our clients. And the format is basically this: <Street Address><Ste or Office number> | <City> However, some of our client addresses are incredibly long and fill the whole line and that causes the line to break and <City> to go to another line. The problem is that the "|" also breaks to the next line and aesthetically it's not the greatest. So what I'm trying to figure out is if the combined address field is longer than the textbox and forces <City> to break to the next line, I'd like to suppress the "|" and have the break as is so it would effectively be: <Street Address><Ste or Office number> <City> I looked through the forums and I saw the threads about using Text Measure, and I've used simple suppression rules before - I'm just at a bit of a loss at how to effectively combine the two so that the suppression rule is triggered when the address fields spans the whole text box length. Thanks! Quote Link to comment Share on other sites More sharing options...
step Posted August 31, 2016 Share Posted August 31, 2016 You can give this a shot: function AllowPipe(input){ var tm = new FusionProTextMeasure; tm.font = 'Helvetica'; tm.pointSize = '12 pt'; tm.maxWidth = FusionPro.inValidation ? 7200 : GetSettableTextWidth(FindTextFrame(FusionPro.Composition.CurrentFlow.name)); tm.CalculateTextExtent(input); return tm.textLines == 1; } var address = [Field("Street Address"), Field("Ste or Office number"), Field("City")].filter(String).join(' '); if (AllowPipe(address) && Field("City")) address = address.replace(' ' + Field("City"), ' | ' + Field("City")); return address; Make sure that you give the text frame that will be returning the rule a unique name. Otherwise, you'll have to manually specify the width of the text frame (in 1/100th's of a point). Then in the rule editor, make sure that you've checked "Re-evaluate this rule for every text flow." Quote Link to comment Share on other sites More sharing options...
stephsal Posted August 31, 2016 Author Share Posted August 31, 2016 Thanks for the response! There's additional functions I'm trying to add to this as well and while the validate button says the expression is OK, it's appearing as {Rule_Address_Format} in my template preview and I'm not sure what I'm doing wrong now. Here's the code. In addition to the Pipe suppression, I made an abbreviation rule and a secondary address suppression (Actually that isn't working either now) if the client doesn't have a Suite or office number. var fieldaddress = Field("address"), fieldaddress2 = Field("address2"), tm = new FusionProTextMeasure, address = [Field("address"), Field("address2"), Field("city")].filter(String).join(' '); //Street Abbreviations function AddressRules(){ fieldaddress = fieldaddress.replace("Boulevard", "Blvd").replace("Street", "St").replace("Terrace","Ter").replace("Avenue","Ave").replace("Road","Rd"); return fieldaddress; } //Secondary Address Suppression function SuppressAddr2(){ if (fieldaddress2 == "") return ""; else return ', '+fieldaddress2; } //Allow Pipe Rule function AllowPipe(input){ tm.font = 'Lato Bold'; tm.pointSize = '87 pt'; tm.maxWidth = FusionPro.inValidation ? 7200 : GetSettableTextWidth(FindTextFrame(FusionPro.Composition.CurrentFlow.FormatAddress)); tm.CalculateTextExtent(input); return tm.textLines == 1;} if (AllowPipe(address) && Field("city")) address = address.replace(' ' + Field("city"), ' | ' + Field("city")); return address; Quote Link to comment Share on other sites More sharing options...
step Posted August 31, 2016 Share Posted August 31, 2016 Thanks for the response! There's additional functions I'm trying to add to this as well and while the validate button says the expression is OK, it's appearing as {Rule_Address_Format} in my template preview and I'm not sure what I'm doing wrong now. Here's the code. In addition to the Pipe suppression, I made an abbreviation rule and a secondary address suppression (Actually that isn't working either now) if the client doesn't have a Suite or office number. var fieldaddress = Field("address"), fieldaddress2 = Field("address2"), tm = new FusionProTextMeasure, address = [Field("address"), Field("address2"), Field("city")].filter(String).join(' '); //Street Abbreviations function AddressRules(){ fieldaddress = fieldaddress.replace("Boulevard", "Blvd").replace("Street", "St").replace("Terrace","Ter").replace("Avenue","Ave").replace("Road","Rd"); return fieldaddress; } //Secondary Address Suppression function SuppressAddr2(){ if (fieldaddress2 == "") return ""; else return ', '+fieldaddress2; } //Allow Pipe Rule function AllowPipe(input){ tm.font = 'Lato Bold'; tm.pointSize = '87 pt'; tm.maxWidth = FusionPro.inValidation ? 7200 : GetSettableTextWidth(FindTextFrame(FusionPro.Composition.CurrentFlow.FormatAddress)); tm.CalculateTextExtent(input); return tm.textLines == 1;} if (AllowPipe(address) && Field("city")) address = address.replace(' ' + Field("city"), ' | ' + Field("city")); return address; The reason that it validates correctly and doesn't display the right thing is this: tm.maxWidth = FusionPro.inValidation ? 7200 : GetSettableTextWidth(FindTextFrame(FusionPro.Composition.CurrentFlow.[color="Red"]FormatAddress[/color])); That line of code sets the max width to the width of the current text frame. At the point of validation, the width of the current text frame is not known so I've manually set it to 7200 (or 1 inch) for validation purposes. "FormatAddress" is not a property of FusionPro.Composition.CurrentFlow. That should be changed to: tm.maxWidth = FusionPro.inValidation ? 7200 : GetSettableTextWidth(FindTextFrame(FusionPro.Composition.CurrentFlow.name)); Or (assuming your text frame is named "FormatAddress"): tm.maxWidth = FusionPro.inValidation ? 7200 : GetSettableTextWidth(FindTextFrame("FormatAddress")); Once you fix that, you probably still won't get the results you're looking for because you don't call either of the functions that you created. I think you want to do something like this: function AllowPipe(input){ tm = new FusionProTextMeasure; tm.font = 'Lato Bold'; tm.pointSize = '87 pt'; tm.maxWidth = FusionPro.inValidation ? 7200 : GetSettableTextWidth(FindTextFrame(FusionPro.Composition.CurrentFlow.name)); tm.CalculateTextExtent(input); return tm.textLines == 1; } var replace = { 'Boulevard': 'Blvd', 'Street': 'St', 'Terrace': 'Ter', 'Avenue': 'Ave', 'Road': 'Rd' }; var address = [ [Field("address"), Field("address2")].filter(String).join(', '), Field("city") ].filter(String).join(' | '); for (var find in replace) address = address.replace(new RegExp(find, 'gi'), replace[find]); if (!AllowPipe(address)) address = address.replace(' | ', ' '); return address; 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.