Kim Posted October 24, 2012 Share Posted October 24, 2012 Hi, I've got a card that will have different phone number fields and an email field. Usually there will be office, direct, cell and fax phone number fields plus an email field. But sometimes there is just one or two phone number fields and the email field. Right now I've got two separate text frames that return a group of phone numbers on the first line and the fax number (if present) and email on the second line. I've got two rules for these lines: var phone = { O: Field("Office"), DD: Field("Direct Dial"), C: Field("Cell"), }; var result = []; for (var p in phone) if (phone[p]) result.push(p + ": " + phone[p]); return result.join(" | "); and var email = { F: Field("Fax"), E: Field("Email Address"), }; var result = []; for (var e in email) if (email[e]) result.push(e + ": " + email[e]); return result.join(" | "); It all works great when I've got the multiple phone numbers for the first line. But when I only have one or two phone numbers and email I'd like to be able to combine and have all of them on one line or the phone numbers on line 1 and email on line 2 when the email address is too long to fit. I've been trying to figure out how to use a non-breaking space so that I don't wind up with the E: on the first line and the email address wrapping down on a second line but I can't get it to work. Example: I get this with my current two rule setup: O: 123-456-7890 F: 123-456-7890 | E:personsemailaddress@somewhere.com I'd like to have: O: 123-456-7890 | F: 123-456-7890 E:personsemailaddress@somewhere.com But when I put everything into one rule, I'm sometimes winding up with: O: 123-456-7890 | F: 123-456-7890 | E: personsemailaddress@somewhere.com I thought if I could get a to work for the E: I could keep the email part together and get the entire email section to go onto line 2 when it's too long to fit on the first line with a phone number. I tried: var phone = { O: Field("Office"), DD: Field("Direct Dial"), C: Field("Cell"), F: Field("Fax"), E: Field("Email Address"), }; var result = []; for (var p in phone) if (phone[p]) result.push(p + ":" + RawTextFromTagged(" ") + phone[p]); return result.join(" | "); but it doesn't work. It still wraps the email with the E: on line 1. I guess I'm also going to have a problem with a | left on the end of line one anyway too, right? So maybe this isn't really do-able? Any ideas? (Dan are you out there?) Quote Link to comment Share on other sites More sharing options...
esmith Posted October 25, 2012 Share Posted October 25, 2012 I'm thinking this would be a good use of the TextMeasure() method where you would determine whether or not the additional data would fit on one line and if not, add a break tag plus the additional data. I know there are other threads with examples of the method's use if you want to give it a go. Quote Link to comment Share on other sites More sharing options...
Kim Posted October 25, 2012 Author Share Posted October 25, 2012 So a fresh look and I appear to have been over thinking it. result.push(p + ": " + phone[p]); seems to give me what I want to keep the email address section together and going to the 2nd line when needed. So now all I need to figure out is if it's possible to determine when the | would be the last element on line 1 and not show it? Eric -- thanks for the suggestion, I'll see what I can find about TextMeasure. Quote Link to comment Share on other sites More sharing options...
Kim Posted October 25, 2012 Author Share Posted October 25, 2012 Eric -- having trouble wrapping my head around how I'd accomplish this with TextMeasure. Do you have a specific example you could point me to? Not sure how I'd work out a break with the way the rule combines the fields. Quote Link to comment Share on other sites More sharing options...
esmith Posted October 25, 2012 Share Posted October 25, 2012 Here's my (admittedly dirty) solution: var phone = ["O : 555-123-4567","DD: 555-123-6789","C: 555-123-2345","F: 555-123-3456","E: someone@somewhere.com"]; var result = ""; var test = ""; var tm = new FusionProTextMeasure; var frameWidth = 3; tm.pointSize = "10 pt"; tm.font = "Helvetica"; tm.useTags = true; for (var p=0; p<phone.length; p++) { if (phone[p] != "") { test += phone[p] + " | "; tm.CalculateTextExtent(test); if (tm.textWidth < frameWidth * 7200) result += phone[p] + " | "; else { test = phone[p] + " | "; result += "<br />" + phone[p] + " | "; } } } result = result.replace(/\|\s<br\s\/>/g,"<br />") return Left(result,result.length-2); Quote Link to comment Share on other sites More sharing options...
Kim Posted October 25, 2012 Author Share Posted October 25, 2012 Thanks for the quick response, Eric. I copied your code but didn't get any value returned -- I'll play around with it. I was trying to keep things simple and tried this variation on my previous code: var phone = { O: Field("Office"), DD: Field("Direct Dial"), C: Field("Cell"), F: Field("Fax"), }; var result = []; for (var p in phone) if (phone[p]) result.push(p + ": " + phone[p]); if ((result.push(p + ": " + phone[p])) == 1) return result.join(" | ") + "E: " + Field("Email Address"); else return result.join(" | ") + "<br>" + "E: " + Field("Email Address"); Quote Link to comment Share on other sites More sharing options...
esmith Posted October 25, 2012 Share Posted October 25, 2012 (edited) I revised my code to use an associative array like you originally had, but not witten as you originally had it. Still, I think it should be fairly easy to adapt to your situation: var phone = []; phone["O"]="555-123-4567"; // your office number phone["DD"]=""; // your direct dial number phone["C"]="555-123-2345"; // your cell number phone["F"]=""; // your fax number phone["E"]="someone@where.com"; // your email address var result = ""; var test = ""; var tm = new FusionProTextMeasure; var frameWidth = 4; // width of your text frame in inches tm.pointSize = "10 pt"; // your point size here tm.font = "Helvetica"; // your font here tm.useTags = true; for (var p in phone) { if (phone[p] != "") { test += p + ": " + phone[p] + " | "; tm.CalculateTextExtent(test); if (tm.textWidth < frameWidth * 7200) result += p + ": " + phone[p] + " | "; else { test = p + ": " + phone[p] + " | "; result += "<br />" + p + ": " + phone[p] + " | "; } } } result = result.replace(/\|\s<br\s\/>/g,"<br />"); return Left(result,result.length-2); Edited October 25, 2012 by esmith fixed leading data prefix after break tag caught by Kim below. Quote Link to comment Share on other sites More sharing options...
Kim Posted October 25, 2012 Author Share Posted October 25, 2012 Wow, Eric. This is great. The only thing it didn't do was the E: on the <br> part so I amended that result line to: result += "<br />" + p + ": " + phone[p] + " | "; Quote Link to comment Share on other sites More sharing options...
esmith Posted October 25, 2012 Share Posted October 25, 2012 Thanks. I fixed the above code with your catch so that it works if I ever come back looking for a way to do this myself. Quote Link to comment Share on other sites More sharing options...
Kim Posted October 25, 2012 Author Share Posted October 25, 2012 (edited) ah, I always forget that when I copy code in here it truncates the rest of my message. Following the code was my heartfelt thanks for your help. I truly appreciate you taking the time to work this out for me. I'm used to Dan usually swooping in to the rescue so it's great to know there is another javascript god on this forum. You are my hero. Thanks so much. Edited October 25, 2012 by Kim Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted October 25, 2012 Share Posted October 25, 2012 ah, I always forget that when I copy code in here it truncates the rest of my message. Following the code was my heartfelt thanks at your help. I truly appreciate you taking the time to work this out for me. I'm used to Dan usually swooping in to the rescue so it's great to know there is another javascript god on this forum. You are my hero. Thanks so much. That's great that Eric could help out. That's the way the User Community is supposed to work. Eric is my hero too! Just a couple of suggestions: When you post, click the "Go Advanced" button. Then, when you paste in code, you can select it and click the # button to make it show up in a code block, like in my and Eric's posts. Also, you can check the the "Disable smilies in text" box, to prevent vBulletin from helpfully replacing certain combinations of letters and punctuation (like in E:personsemailaddress@somewhere.com) with emoticons. Quote Link to comment Share on other sites More sharing options...
dreimer Posted October 25, 2012 Share Posted October 25, 2012 I agree with Kim, thanks to everyone who helps me out with my issues as well, especially the JavaScript!!!! Quick question, is the Text Measure Function available to versions before FP8? Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted October 25, 2012 Share Posted October 25, 2012 Quick question, is the Text Measure Function available to versions before FP8? Yes, the FusionProTextMeasure object has been available in every version of FusionPro. (It actually used to be called DL100TextMeasure in the ancient times before FusionPro, and that syntax will still work.) Quote Link to comment Share on other sites More sharing options...
dreimer Posted October 26, 2012 Share Posted October 26, 2012 Guess that makes me ancient, since I have used this program since the DL100 days!! 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.