gregmaze Posted July 11, 2017 Share Posted July 11, 2017 Greetings all... I have a javascript rule I am trying to create that I was hoping someone might help with a problem. I have a business card that has a Name Line and a degree line. The user can choose up to 3 degrees, which will be separated by a comma. If the Degrees can fit on the Name line the customer would like to have it appear there. If all the degrees cannot fit on the name line together, all degrees should then be on the 2nd line. The script below is what I have so far. I have it pretty much working, except when the degrees go to the 2nd line. I am having a problem with commas and spaces. Here is the 2 versions it should look like. Mary Smith, CFO or Mary Smith CFO, COO, CEO currently for the 2nd line option it appears Mary Smith CFOCOOCEO, here is the code: var Name = [Field("Name")] var Degree = [Field("Degree1") + Field("Degree2") + Field("Degree3")]; var result = ""; var test = ""; var tm = new FusionProTextMeasure; var frameWidth = 1.72; tm.pointSize = "10 pt"; tm.font = "DINOT-Medium"; tm.useTags = true; for (var p=0; p<Name.length; p++) { if (Name[p] != "" + Degree[p] !="") { test += Name[p] + Degree[p]; tm.CalculateTextExtent(test); if (tm.textWidth < frameWidth * 7200) result += Name[p] + ", " + Degree[p]; else { test += Name[p] + Degree[p]; result += Name[p] + "<br />" + (Degree[p] + ", "); } } } return Left(result,result.length); Thank you in advance for the help if possible. Greg Mac OS 10.11.3 Fusion Pro 10.0.3 Quote Link to comment Share on other sites More sharing options...
step Posted July 11, 2017 Share Posted July 11, 2017 var result = [ Field("Name"), Field("Degree1"), Field("Degree2"), Field("Degree3") ].filter(String).join(', '); var tm = new FusionProTextMeasure; tm.pointSize = "10 pt"; tm.font = "DINOT-Medium"; tm.maxWidth = 1.72 * 7200; tm.CalculateTextExtent(result); return tm.textLines > 1 ? result.replace(', ', '<br/>') : result; Quote Link to comment Share on other sites More sharing options...
gregmaze Posted July 12, 2017 Author Share Posted July 12, 2017 Hello Stepp, Thank you very much for the help. This works perfectly. A much simpler code... I enjoy reading your's and others' comments on this forum. This is a great learning place. Thanks again 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.