traba5058 Posted October 24, 2012 Share Posted October 24, 2012 I've been using Marcomm Central & Fusion Pro since Feb, so I am still fairly new at javascript. I am setting up a new business card template for Marcomm Central using FusionPro and need help. This client uses one font for text and one font for numbers. This means the number font needs to be used for phone & mobile numbers as well as the zip code & numbers in the address 1 & address 2 fields. FusionPro makes it very easy to assign a font to a field, so I can easily assign the font to the phone & mobile numbers as well as the zip code field. I'm having problems with address1 & address2 fields. Is there javascript or a setting that will look for numbers in a field and use a font? Please help. Quote Link to comment Share on other sites More sharing options...
esmith Posted October 24, 2012 Share Posted October 24, 2012 Create the following text rule: var address = [color="Red"]your address field[/color]; address = address.replace(/(\d+)/g,"<f name='[color="Red"]number_font[/color]'>$1</f>"); return address; (Alternatively, you could build your entire address block (street, city, state, zip, etc) for your variable.) Place the rule in a text frame and apply the text font you want. The code will replace all number sequences in your variable string with a tagged version of same string(s) using the number font you add to the code. Be sure to check 'Treat returned strings as tagged text' in the rule. Quote Link to comment Share on other sites More sharing options...
traba5058 Posted October 24, 2012 Author Share Posted October 24, 2012 Thanks Eric! I updated your rule to read var address = Field("Street 1"); address = address.replace(/(\d+)/g,"<f name='Sebastion Light UCF'>$1</f>"); return address; and var address = Field("Street 2"); address = address.replace(/(\d+)/g,"<f name='Sebastion Light UCF'>$1</f>"); return address; I also checked the treat tagged text box. The preview is returning a different font for the numbers in the field but it looks like a default font or something. It doesn't match the font in the phone & mobile number fields or the zip code field. I entered the name of the font as it appears in the drop down in FusionPro. Is there a different way it needs to be entered? Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted October 24, 2012 Share Posted October 24, 2012 You need double-quotes in the markup tags. Try this instead: return Field("Street 2").replace(/(\d+)/g,'<f name="Sebastion Light UCF">$1</f>');Also, you might not have the correct font name. Do a regular composition (not a Preview) and look in the composition log (.msg) file for any font warnings. You can always determine the correct font name to use in an <f> tag by creating a Formatted Text resource, entering some text in the desired font, then exiting the Text Editor and clicking "View Source." That will show you the correct <f name=***> tag. Quote Link to comment Share on other sites More sharing options...
dreimer Posted October 24, 2012 Share Posted October 24, 2012 Both rules work for me but I have a problem when the street name is a number. For example 123 86th Ave is returned 12386th Ave. Quote Link to comment Share on other sites More sharing options...
esmith Posted October 24, 2012 Share Posted October 24, 2012 Your updates look correct to me. When I google the font you are using it "corrects" the name to be "Sebastian Light UCF" -- are you sure the name isn't misspelled? If that is not the issue, you may want to temporarily try another (more common) font in the tag to see if the problem is with the specific font or something broader. Also, if you reverse the font assignments (for testing only) does "Sebastion Light UCF" preview correctly for the alpha characters? Quote Link to comment Share on other sites More sharing options...
esmith Posted October 24, 2012 Share Posted October 24, 2012 Both rules work for me but I have a problem when the street name is a number. For example 123 86th Ave is returned 12386th Ave. Good catch dreimer! The code vallidates correctly with a space in that scenario but does not appear to format it correctly in the preview. I tweaked my original code and changed the single/double quotes that Dan suggested (which I was unaware of): var address = '123 21South Main Street, Suite 24A 3 SW 1342A5692'; address = address.replace(/\s/g," ").replace(/(\d+)/g,'<f name="FolioSS-Bold">$1</f>'); return address; Quote Link to comment Share on other sites More sharing options...
dreimer Posted October 24, 2012 Share Posted October 24, 2012 Perfect, the new code worked correctly. Getting great stuff off this forum of late, thank you everyone!!! Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted October 24, 2012 Share Posted October 24, 2012 (edited) Good catch dreimer! The code vallidates correctly with a space in that scenario but does not appear to format it correctly in the preview. I tweaked my original code and changed the single/double quotes that Dan suggested (which I was unaware of): var address = '123 21South Main Street, Suite 24A 3 SW 1342A5692'; address = address.replace(/\s/g," ").replace(/(\d+)/g,'<f name="FolioSS-Bold">$1</f>'); return address; That will work, except that you're replacing every space with a non-breaking space, which will prevent the address from wrapping to multiple lines properly. If that's not an issue in your job, then it's fine. If, however, you do want to maintain the breaking spaces, then you need to do something like this instead: function replace_helper(match, digits, spaces) { return '<f name="Courier New">' + digits + '</f>' + Array(spaces.length + 1).join("&[size=3]#[/size]32;"); } return Field("Address").replace(/(\d+)(\s*)/g, replace_helper);More info: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_function_as_a_parameter Edited October 24, 2012 by Dan Korn typo Quote Link to comment Share on other sites More sharing options...
traba5058 Posted October 24, 2012 Author Share Posted October 24, 2012 Thanks to All! It was the quotes & spelling of Sebastian. I'm using: var address = Field("Street 1"); address = address.replace(/\s/g," ").replace(/(\d+)/g,'<f name="Sebastian Light UCF">$1</f>'); return address; and var address = Field("Street 2"); address = address.replace(/\s/g," ").replace(/(\d+)/g,'<f name="Sebastian Light UCF">$1</f>'); return address; Can you tell me what you mean by breaking? I have copyfit on and hyphenation off & do not break on copyfit on. I do not want address 1 to move to the next line & I do not want address 2 to move to the next line. I want copy to shrink to fit in address block. Do I have to worry about breaking? Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted October 24, 2012 Share Posted October 24, 2012 Can you tell me what you mean by breaking? I have copyfit on and hyphenation off & do not break on copyfit on. I do not want address 1 to move to the next line & I do not want address 2 to move to the next line. I want copy to shrink to fit in address block. Do I have to worry about breaking? No, if you don't want the address to break to multiple lines, then what you have should be fine. 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.