Jump to content

Recommended Posts

Posted

I need to figure out the proper code to make this happen.

 

I have three fields; Phone, Fax & Cell. When all three fields are present they should like this below.

Office: 804.555.5555 ext. 3001 • Fax: 804.555.5555 • Cell: 804.555.5555

But I may only have two fields or even one field. How can I make it look like these examples:

Office: 804.555.5555 ext. 3001 • Cell: 804.555.5555 or

Fax: 804.555.5555 • Cell: 804.555.5555 or

Office: 804.555.5555 ext. 3001 • Fax: 804.555.5555

Office: 804.555.5555 ext. 3001 or

Cell: 804.555.5555

 

Thanks in advance

Posted

You probably want to put your phone fields (or phone formatting rules if you have them set up) in an array. Filter out the elements in the array that don't contain data for a specific record, and then join them with a bullet or the HTML entity of a bullet (•). Like this:

 

 Array.prototype.filter = function(fun /*, thisp*/) {
   'use strict';

   if (!this) {
     throw new TypeError();
   }

   var objects = Object(this);
   var len = objects.length >>> 0;
   if (typeof fun !== 'function') {
     throw new TypeError();
   }

   var res = [];
   var thisp = arguments[1];
   for (var i in objects) {
     if (objects.hasOwnProperty(i)) {
       if (fun.call(thisp, objects[i], i, objects)) {
         res.push(objects[i]);
       }
     }
   }

   return res;
 }

//========== You can erase everything above this line if you are using FP8 or later  ============//



// Replace fields with your names or the rules you've used to format the numbers
var office = Field("Office") // Or Rule("FormatPhone_Office)
var fax = Field("Fax");
var cell = Field("Cell");

var numbers = ["Office: " + office,"Fax: " + fax,"Cell: " + cell];

return numbers.filter(function(m){return m.match(/.*\s(?=.)/);}).join(" • ");

 

By the way, since your signature says you're running FP6, I included the array prototype for the filter method at the start of the code so that it will work for you. If you have upgraded to 8 or 9, you won't need that block of code anymore and I commented that thusly.

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...