Jump to content

Right justified text and unwanted spaces


Brad Sawatzky

Recommended Posts

I'm updating a business card template I created a long time ago and running into some trouble switching from left to right justified text. Actually the switch was easy, it's the spaces in between phone numbers that are the problem.

 

My variable text box includes:

Address1

Address2

Phone1 Label Phone1 Phone2 Label Phone2

Phone3 Label Phone3 Phone4 Label Phone4

Phone5 Label Phone5

Email

URL

 

When it was all left justified, everything worked fine, but now that it's right justified, I have an unwanted space at the right hand side when there is no Phone2. (and as no surprise, same with Phone3 when no Phone4 exists.)

 

I have Hide Phone Label Rules in place for all my Labels, and Phone Format Rules for my numbers, the only exception is the Rule for Phones3 and 4 which looks like this:

 

var dirOut = "";

if (Trim(Field("Phone3")) != "") {dirOut += Rule("Hide Phone3 Label Rule") + (Rule("Phone3 Format Rule"));}

if (Trim(Field("Phone4")) != "") {if (dirOut != "") {dirOut += Rule("Hide Phone4 Label Rule") + Rule("Phone4 Format Rule");}

else {dirOut += Rule("Hide Phone4 Label Rule") + Rule("Phone4 Format Rule");

}

}

return dirOut;

 

Getting late in the day, hope I've explained everything okay.

 

If anyone has any ideas as to how I can get rid of those nasty, unwanted spaces, I'd sure appreciate it.

 

Thanks,

Link to comment
Share on other sites

Hey Dan,

 

My "Hide Phone2 Label Rule" returns "Phone2 Label" if "Phone2" contains a value. If "Phone2" doesn't contain a value, "Phone2 Label" returns nothing. It looks like this:

 

if (Field("Phone2") == "")

return "";

else

return Field("Phone2 Label");�

 

My "Phone2 Format Rule" is from the "Change phone format Rule" template, and looks in part like this:

 

if(CaseSelection == "Format 2")

 

{

 

var formatStyle01 = "$1 $2"; //simple 7 digit phone

 

var formatStyle02 = "$1 $2 $3"; //simple 10 digit phone

 

var formatStyle03 = "+$1 $2-$3-$4"; //10 digit phone starts with 1

 

var formatStyle04 = "$1-$2-$3 ext.$4"; //10 digit phone with extension

 

var formatStyle05 = "+$1 $2-$3-$4 ext.$5"; //10 digit phone starts with 1 with extension

 

var formatStyle06 = "$1-$2 ext.$3"; //7 digit phone with extension

 

 

 

var thisNumber = Field(Var1);

 

 

 

return formatNumber(Trim(thisNumber));

 

}�

 

The exception I mentioned above for Phones 3 & 4 I had help with (if thats not already obvious) and it was back in 2009, can't remember for sure what it remedied.

 

I monkey'd around a bit after posting and was able to get the desired result by adding a space in my variable text box at the right side of "Address1", "Address2", "Phone5", "Email" and "URL".

When I compared the old and new verisons, I noticed that previously I had 2 spaces between "Phone1" and "Phone2 Label" and between "Phone3" and "Phone4 Label". Adding an additional space doesn't solve this problem.

I tried changing the last line of the Phone3 and 4 rule to return Trim(dirOut); but didn't get the result I was hoping for.

I'll keep playing around with it, but if there is any advice you can offer, I'm all ears.

 

Thanks Dan

Link to comment
Share on other sites

I'll keep playing around with it, but if there is any advice you can offer, I'm all ears.

Well, okay, it's still hard to figure out just from looking at the rules, without the rest of the job to actually try things out. If you want to post the collected job, someone might be able to take a look at it.

Link to comment
Share on other sites

Hey Dan,

I continued playing around with it, but I'm still stuck. I'll attach the collected file, and hopfully someone can point me in the right direction.

Record 1 works the way I'd like it to, with everything justified to the right. Record 2 has no Phone 2, and I'd like Phone1 to justify to the right, but it won't because of the 2 spaces I have in my variable text box.

Record 3 has no Phone3 or 4, and both Phone1 and Phone3 don't justify to the right. I know it's because of the spaces I have in my variable text box, but I'm not sure how to get rid of them in the case of having no Phone2 or 4.

 

Thanks again,

46753 Total E&P BC (2).zip

Link to comment
Share on other sites

This might work for you:

 

Put this code in your JavaScript Globals (to format your numbers):

function formatNumber(number01){

var formatStyle01 = "$1 $2"; 			//simple 7 digit phone

var formatStyle02 = "$1 $2 $3";			//simple 10 digit phone

var formatStyle03 = "+$1 $2-$3-$4";		//10 digit phone starts with 1

var formatStyle04 = "$1-$2-$3 ext.$4";		//10 digit phone with extension

var formatStyle05 = "+$1 $2-$3-$4 ext.$5";	//10 digit phone starts with 1 with extension

var formatStyle06 = "$1-$2 ext.$3";		//7 digit phone with extension



var pattern01 = /^(\d{3})[^\d]*(\d{4})$/;   						

//   //2201727 or 220-1727 or 220- 1727

var pattern02 = /^[\D]*(\d{3})[\D]*(\d{3})[\D]*(\d{4})$/;   				

// 8002201727 or 800-220-1727 or (800)220-1727 or (800) 220-1727

var pattern03 = /^\+?(\d{1})[\D]*(\d{3})[\D]*(\d{3})[\D]*(\d{4})$/;   			

// 18002201727 or 1-800-220-1727 or +1 (800) 220-1727

var pattern04 = /^[\D]*(\d{3})[\D]*(\d{3})[\D]*(\d{4})\D*[x#n]\D*(\d+)$/;		

// 800-220-1727 ext 12345 or (800) 220-1727 ext 12345

var pattern05 = /^\+?(\d{1})[\D]*(\d{3})[\D]*(\d{3})[\D]*(\d{4})\D*[x#n]\D*(\d+)$/;	

// 1-800-220-1727 ext 12345 or +1 (800) 220-1727 ext 12345

var pattern06 = /^(\d{3})[\D]*(\d{4})\D*[x#n]\D*(\d+)$/;   				

// 2201727 ext 1234 or 220-1727 ext 1234 or 220- 1727 ext 1234

var patternEndExt = /(.)[x#n](.)/;

var patternStart1 = /^[\D]*[1]/;



if(number01.match(pattern01)){

	number01 = number01.replace(pattern01, formatStyle01);

	return number01;

} else if(number01.match(pattern02)){

	number01 = number01.replace(pattern02, formatStyle02);

	return number01;

} else if(number01.match(pattern03)){

	if (number01.match(patternStart1)){

		number01 = number01.replace(pattern03, formatStyle03);

		return number01;

	} else {

		return number01;

	}

} else if(number01.match(pattern04)){

		number01 = number01.replace(pattern04, formatStyle04);

		return number01; 

} else if(number01.match(pattern05)){

		number01 = number01.replace(pattern05, formatStyle05);

		return number01;

}  else if(number01.match(pattern06)){

		number01 = number01.replace(pattern06, formatStyle06);

		return number01;

} else {

	//return "no match any pattern";

	return number01;

}	

}

 

Create a new text rule and name it something like "FormattedNumbers" (make sure you have "treat returned strings as tagged text" checked):

var result = "";

for (var i=1; i<6; i++){
   var br = (i%2 == 0) ? "  " : "<br>";
   result += (Field("Phone" + i) != "" ) ? br + Trim(Field("Phone" + i + " Label")) + " " + formatNumber(Trim(Field("Phone" + i)))  : "";
}
return result.replace(/^<br>/,"");

 

And finally, replace the number rules in the text editor with that rule. So it will simply read:

«Select Address Rule»  «Postal Code»
«FormattedNumbers»
«Email»
«URL»

 

Hope that helps!

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