Jump to content
Welcome to the new FusionPro User Forum! ×

Formatting phone number fields


GSBjay

Recommended Posts

Hey guys,

I'm trying to find a script to format some phone numbers in a business card but I'm new to javascripts. In the example below, there can be 3 instances.

 

Instance 1: (if all 3 numbers exist then it would look like this, with the fax breaking to a new line)

 

<phone> | <mobile>

<fax>

 

 

Instance 2: (if only phone and fax then it would look like this)

 

<phone> | <fax>

 

 

Instance 3: (if only phone and mobile then it would look like this)

 

<phone> | <mobile>

 

 

I've been given a code by the support group but it's not behaving well.

 

if(Field("Mobile") !="")

return 'T '+Field("telephone") + ' | M '+Field("Mobile") + '<br>F ' + Field("Fax");

else

return 'T '+Field("telephone") + ' | F '+Field("Fax");

 

The double blank space I put in ' | M ' is somehow purged when previewed.

Does anyone know how to retain the blank spaces?

 

Thanks,

Jay

Edited by GSBjay
Link to comment
Share on other sites

The double blank space I put in ' | M ' is somehow purged when previewed.

Does anyone know how to retain the blank spaces?

To insert more than one space, you need to use the HTML entity for a non-breaking space (in place of an actual space) and enable tagging by checking the appropriate box in the rule window:

 

Link to comment
Share on other sites

Thanks Eric,

I've updated the script with your instructions and it retained the blank spaces. After testing the card, I realize instance 3 is not working. When only <telephone> and <mobile> is present, it looks like this:

 

<telephone> | <mobile>

F

The letter "F" appears in its own line when no fax number is present.

 

 

This is my current script.

if(Field("Mobile") !="")

return 'T '+Field("telephone") + "  |  M "+Field("Mobile") + '<br>F ' + Field("Fax");

else

return 'T '+Field("telephone") + "  |  F "+Field("Fax");

I do not have a script for instance 3. Do anyone know to make all 3 instances work?

 

Thanks,

Jay

Link to comment
Share on other sites

Then update your current script with this.

 

if(Field("Mobile") !="")

return 'T '+Field("telephone") + "  |  M "+Field("Mobile") + Rule("JustFax_RULE");

else

return 'T '+Field("telephone") + "  |  F "+ Field ("Fax");

Link to comment
Share on other sites

This is almost exactly the same question as in this thread:

http://forums.printable.com/showthread.php?t=1619

 

However, your requirements are a little more complicated, because the delimiters (separators) between the fields are not constant. Specifically, your first delimiter is " | ", and your second delimiter is "<br>". So the simple method which Eric suggested in that other thread of appending items to a result string as you go won't quite work.

 

Instead, I would use a variation on my more generalized solution from that other thread, which first puts each separate field and its label into an array. Then we can deal with things depending on how many non-empty items we end up with. Try this:

var Entries = [
   "T ", TaggedFromRaw(Field("telephone")),
   "M ", TaggedFromRaw(Field("Mobile")),
   "F ", TaggedFromRaw(Field("Fax")),
];

var items = [];
for (var i = 0; i < Entries.length; i += 2)
 if (Entries[i] && Entries[i+1])
   items.push(Entries[i] + Entries[i+1]);

return items.slice(0,2).join(" | ") + (items[2] ? "<br>" + items[2] : "");

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...