Jump to content

Business card contacts array


MeeshKB

Recommended Posts

I am having trouble with a rule for formatting business card contacts. It's not filtering as I would expect. The rule is as follows:

 

var tel = Rule("Change Tel format Rule")
var cell = Rule("Change Cell format Rule")
var dir = Rule("Change Dir format Rule")
var fax = Rule("Change Fax format Rule");
var numbers = ['<color name="c0m0y0k50">' + '<t>' + "t. " + '<z newsize=7>' + '<color name="Black">' + tel,
'<z newsize=5>' + '<color name="c0m0y0k50">' + '<t>' + "c. " + '<z newsize=7>' + '<color name="Black">' + cell,
'<z newsize=5>' + '<color name="c0m0y0k50">' + '<t>' + "d. " + '<z newsize=7>' + '<color name="Black">' + dir,
'<z newsize=5>' + '<color name="c0m0y0k50">' + '<t>' + "f. " + '<z newsize=7>' + '<color name="Black">' + fax,];
return numbers.filter(function(m){return m.match(/.*\s(?=.)/);}).join('<p>');

and is currently returning this:

http://i141.photobucket.com/albums/r42/Turtlegirl203/Public/Professional/e4dd43cb-314b-405e-8553-6ba6ce168a70_zpsf24618c1.jpg

 

It isn't filtering the alpha characters for the contacts which don't have numbers.

 

It appears that the tab before the alpha character may be causing the issue, but I need a tab there to right align those characters. Any thoughts on how to get around this?

Edited by MeeshKB
Link to comment
Share on other sites

It's not clear to me what you expect that Array.filter function with the String.match function and the Regular Expression to do. I think the RegExp object says, "match anything followed by a whitespace character followed by any character." I don't see how any of the lines of text would fail to match that, since you're explicitly putting spaces into each one, as part of those labels like "t.". You're also putting markup tags such as "<z newsize=5>" in there, which obviously contain spaces. Remember that the JavaScript engine, which is processing the Regular Expression, doesn't know anything about FusionPro's markup tags; it just sees it all as a string of text, so generally, you don't want to try to apply this kind of text processing to tagged markup. (The "<t>" markup for a tab has nothing to do with what's going on here, since there's no space character in it.)

 

Anyway, it looks like what you're trying to do is suppress the lines which don't have phone numbers in them. The much easier way to do this requires no JavaScript at all. Just set those lines of text directly in the Text Editor, one on each line with a label, a tab, and a variable for the corresponding rule, then select all the lines, click "Paragraph," check the "Suppress if" box, and change the drop-down to "Containing Empty Variables."

Link to comment
Share on other sites

Thank you for the reply, Dan.

 

I have to admit to using that code (kindly provided by someone on this board for another, more complex project) many times without fully understanding how it works. The last line of the code is greek to me, despite my best efforts to understand it. It has worked for me on countless other occasions, which is why I was stumped when it didn't work this time. The only difference in this case seemed to be the tab markup preceding the alpha character.

 

Regardless, you are right. I am overthinking this one. Since the numbers are all on their own lines, I can simply use the suppress function in the text editor.

 

Thanks once again for your assistance. It's much appreciated.

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