Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > The JavaScript Library > Formatting Text

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old May 13th, 2010, 12:03 PM
JulieP JulieP is offline
Junior Community Member
 
Join Date: Aug 2009
Posts: 11
Unhappy Moving lines up if one line is blank

I am trying to build a business card template with eleven possible lines. If one line is left blank, the others should move up. I tried using Dan Korn's code example in his Oct 7th '08 post. I thought I could make it work but I get this error on validation "Function does not return a value". I would greatly appreciate if someone could steer me in the right direction. Here is my clunky code:

Code:
 
//I have eleven possible fields, if certain fields are left blank all the other fields need to move up 1 line.
//Field Rule Vars
var Office = Rule("OFFICERemoveWriteRule");
var Mobile = Rule("MOBILERemoveWriteRule");
var Email = Rule("EMAILRemoveWriteRule");
var Twitter = Rule("SuppressTwitGraph");
var TwitAdr = Rule("twitadrRemoveWriteRule");
var FaceBook = Rule("Suppress Facebk graphic");
var FaceBkAdr = Rule("facebkadrRemoveWriteRule");
var CampusOffice = Rule("CampusOfficeRemoveWriteRule");
var OfficeAddress = Rule("OfficeAdrRemoveWriteRule");
var Phone = Rule("PHONERemoveWriteRule");
var Fax = Rule("FAXRemoveWriteRule");
var CampusWebsite = Rule("WEBSITERemoveWriteRule");
 
//Field Vars
var Ofc = Office ? Office : "";
var Mob = Mobile ? Mobile : "";
var Eml = Email ? Email : "";
var TwitG = Twitter ? Twitter : "";
var TwitA = TwitAdr ? TwitAdr : "";
var FbkG = FaceBook ? FaceBook : "";
var FbkA = FaceBkAdr ? FaceBkAdr : "";
var CampOff = CampusOffice ? CampusOffice : "";
var OffAdr = OfficeAddress ? OfficeAddress : "";
var Phn = Phone ? Phone : "";
var FX = Fax ? Fax : "";
var CampWeb = CampusWebsite ? CampusWebsite: "";
 
var line1 = "";
var line2 = "";
var line3 = "";
var line4 = "";
var line5 = "";
var line6 = "";
var line7 = "";
var line8 = "";
var line9 = "";
var line10 = "";
var line11 = "";
 
if(Ofc && Mob && Eml && TwitA && FbkA && CampOff && OffAdr && Phn && FX && CampWeb)
{
 line1 = Ofc;
 line2 = Mob;
 line3 = Eml;
 line4 = TwitG + TwitA;
 line5 = FbkG  + FbkA;
 line6 = "";
 line7 = CampOff;
 line8 = OffAdr;
 line9 = Phn;
 line10 = Fax;
 line11 = CampWeb;
}
else
  //no Office
   if(Mob && Eml && TwitA && FBKA && CampOff && OffAdr && Phn && FX && CampWeb)
{ 
 line1 = Mob;
 line2 = Eml;
 line3 = TwitG + TwitA;
 line4 = FbkG  + FbkA;
 line5 = "";
 line6 = CampOff;
 line7 = OffAdr;
 line8 = Phn;
 line9 = Fax;
 line10 = CampWeb; 
 line11 = ""
}
 else
  //no Mobile
   if(Ofc && Eml && TwitA && FbkA && CampOff && OffAdr && Phn && FX && CampWeb)
{ 
 line1 = Ofc;
 line2 = Eml;
 line3 = TwitG + TwitA;
 line4 = FbkG  + FbkA;
 line5 = "";
 line6 = CampOff;
 line7 = OffAdr;
 line8 = Phn;
 line9 = Fax;
 line10 = CampWeb;
 line11 = "";
}
 else
 //no Twitter Address
  
  if(Ofc && Mob && Eml && FbkA && CampOff && OffAdr && Phn && FX && CampWeb)
{
 line1 = Ofc;
 line2 = Mob;
 line3 = Eml;
 line4 = FbkG  + FbkA;
 line5 = "";
 line6 = CampOff;
 line7 = OffAdr;
 line8 = Phn;
 line9 = Fax;
 line10 = CampWeb;
 line11 = "";
}
 else
 // no Facebook Address
  if(Ofc && Mob && Eml && TwitA && CampOff && OffAdr && Phn && FX && CampWeb)
{
 line1 = Ofc;
 line2 = Mob;
 line3 = Eml;
 line4 = TwitG + TwitA;
 line5 = "";
 line6 = CampOff;
 line7 = OffAdr;
 line8 = Phn;
 line9 = Fax;
 line10 = CampWeb;
 line11 = "";
}
 else
 // no TwitA & no FaceBkadr
 if(Ofc && Mob && Eml && CampOff && OffAdr && Phn && FX && CampWeb)
{
 line1 = Ofc;
 line2 = Mob;
 line3 = Eml;
 line4 = "";
 line5 = CampOff;
 line6 = OffAdr;
 line7 = Phn;
 line8 = Fax;
 line9 = CampWeb;
 line10 = "";
 line11 = "";
}
else
 // no Mobile & no Twitter
  if(Ofc && Eml && FbkA && CampOff && OffAdr && Phn && FX && CampWeb)
{
 line1 = Ofc;
 line2 = Eml;
 line3 = FbkG  + FbkA;
 line4 = "";
 line5 = CampOff;
 line6 = OffAdr;
 line7 = Phn;
 line8 = Fax;
 line9 = CampWeb;
 line10 = "";
 line11 = "";
}
else
 // no Mobile & no Facebook 
 if(Ofc && Eml && TwitA && CampOff && OffAdr && Phn && FX && CampWeb)
{
 line1 = Ofc;
 line2 = Eml;
 line3 = TwitG + TwitA;
 line4 = "";
 line5 = CampOff;
 line6 = OffAdr;
 line7 = Phn;
 line8 = Fax;
 line9 = CampWeb;
 line10 = "";
 line11 = "";
}
else
 //no Mobile & No Twitter & No Facebook
  if(Ofc && Eml && CampOff && OffAdr && Phn && FX && CampWeb)
{
 line1 = Ofc;
 line2 = Eml;
 line3 = "";
 line4 = CampOff;
 line5 = OffAdr;
 line6 = Phn;
 line7 = Fax;
 line8 = CampWeb;
 line9 = "";
 line10 = "";
 line11 = "";
}
else
 // no phone
 
   if(Ofc && Mob && Eml && TwitA && FbkA && CampOff && OffAdr && FX && CampWeb)
{
 line1 = Ofc;
 line2 = Mob;
 line3 = Eml;
 line4 = TwitG + TwitA;
 line5 = FbkG  + FbkA;
 line6 = "";
 line7 = CampOff;
 line8 = OffAdr;
 line9 = Fax;
 line10 = CampWeb;
 line11 = "";
}
else
 // no fax
   if(Ofc && Mob && Eml && TwitA && FbkA && CampOff && OffAdr && Phn && CampWeb)
{
 line1 = Ofc;
 line2 = Mob;
 line3 = Eml;
 line4 = TwitG + TwitA;
 line5 = FbkG  + FbkA;
 line6 = "";
 line7 = CampOff;
 line8 = OffAdr;
 line9 = Phn;
 line10 = Fax;
 line11 = CampWeb;
}
else
 //nothing is missing
 line1 = Ofc;
 line2 = Mob;
 line3 = Eml;
 line4 = TwitG + TwitA;
 line5 = FbkG  + FbkA;
 line6 = "";
 line7 = CampOff;
 line8 = OffAdr;
 line9 = Phn;
 line10 = Fax;
 line11 = CampWeb;
}
}
var result = line1;
  if (line2 + line3 + line4 + line5 + line6 + line7 + line8 + line9 + line10 + line11)
    result += "<br>\n" + line2 + "<br>\n"+ line3 + "<br>\n"+ line4 + "<br>\n" + line5 +"<br>\n" + line6 +"<br>\n" + line7 
+"<br>\n" + line8 +"<br>\n" + line9 +"<br>\n" + line10 +"<br>\n" + line11;
 
  return result;
Reply With Quote
  #2  
Old May 13th, 2010, 01:55 PM
esmith's Avatar
esmith esmith is offline
Senior Contributor
 
Join Date: Oct 2008
Location: Charlotte, NC
Posts: 869
Default Re: Moving lines up if one line is blank

I admit my eyes glossed over by around the 25th line of your code.
Assuming your fields are named similar to your initial vars at the beginning of your code, I would try something like this:
Code:
// edit field names if necessary to match your data
var info1 = Field("Office");
var info2 = Field("Mobile");
var info3 = Field("Email");
var info4 = Field("Twitter");
var info5 = Field("TwitAdr");
var info6 = Field("FaceBook");
var info7 = Field("FaceBkAdr");
var info8 = Field("CampusOffice");
var info9 = Field("OfficeAddress");
var info10 = Field("Phone");
var info11 = Field("Fax");
var info12 = Field("CampusWebsite");

// do not edit below this comment
var cardInfo = [];
var result = "";
// build an array of the populated fields in your record
for (var i=1 i<=12; i++) {
    var element = "info" + i;
    if (element != "") cardInfo.push(element);
}
// build your return value from the array of data
for (var k=0; k<cardInfo.length; k++) {
    result += cardInfo[k] + "<br>";
}
// remove the trailing break tag
result = Left(result, result.length-4);
return result;
__________________
Eric Smith
Content Developer
Classic
FP 9.3.6, MAC OSX 10.9.4, Acrobat 11.0.09
Reply With Quote
  #3  
Old May 13th, 2010, 02:22 PM
JulieP JulieP is offline
Junior Community Member
 
Join Date: Aug 2009
Posts: 11
Default Re: Moving lines up if one line is blank

Thanks! I knew there was a much better way just didn't know how to get there.
Reply With Quote
  #4  
Old May 13th, 2010, 03:19 PM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,467
Default Re: Moving lines up if one line is blank

You don't need to write any JavaScript code to do this. You can do it all in the Variable Text Editor for the text frame you want the data to appear in. Simply use the "Variable" drop-down and the "Insert" button to enter each data field or rule name on its own line (hitting Enter/Return to break up the lines). Then do a Select-All (Ctrl-A on Windows or Command-A on Mac) and click the "Paragraph" button, then click the box marked "Suppress if." Click OK twice and you're good to go.

P.S. Eric, if you were going to do this in code, you're on the right track, but that's not quite right. A statement such as
Code:
var element = "info" + i;
is simply going to resolve to a string literal with a value of "info1" or "info2", etc., not the value of a variable with that name. There is a way to make that kind of code work, but as I said, this problem doesn't require any coding at all to solve.
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});

Last edited by Dan Korn; May 13th, 2010 at 04:17 PM..
Reply With Quote
  #5  
Old May 13th, 2010, 04:16 PM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,467
Default Re: Moving lines up if one line is blank

Quote:
Originally Posted by Dan Korn View Post
P.S. Eric, if you were going to do this in code, you're on the right track, but that's not quite right. A statement such as
Code:
var element = "info" + i;
is simply going to resolve to a string literal with a value of "info1" or "info2", etc., not the value of a variable with that name. There is a way to make that kind of code work, but as I said, this problem doesn't require any coding at all to solve.
So again, you don't need any code at all to do this, but just as a fun exercise, if you were you do this in JavaScript, this is probably the most succinct solution:
Code:
// Enter all the fields, rules, etc., that you want to output
// one per line, skipping empty lines, here:
var MyFields = [
    Rule("OFFICERemoveWriteRule"),
    Rule("MOBILERemoveWriteRule"),
    Rule("EMAILRemoveWriteRule"),
    Rule("SuppressTwitGraph"),
    Rule("twitadrRemoveWriteRule"),
    Rule("Suppress Facebk graphic"),
    Rule("facebkadrRemoveWriteRule"),
    Rule("CampusOfficeRemoveWriteRule"),
    Rule("OfficeAdrRemoveWriteRule"),
    Rule("PHONERemoveWriteRule"),
    Rule("FAXRemoveWriteRule"),
    Rule("WEBSITERemoveWriteRule"),
];

// Don't edit below here:
var NonEmptyFields = [];
for(var i = 0; i < MyFields.length; i++)
    if(MyFields[i])
        NonEmptyFields.push(MyFields[i]);

return NonEmptyFields.join("<br>");
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
Reply With Quote
  #6  
Old May 13th, 2010, 04:22 PM
JulieP JulieP is offline
Junior Community Member
 
Join Date: Aug 2009
Posts: 11
Default Re: Moving lines up if one line is blank

Thanks Dan! I think I will have to use JS because I am also dealing with 2 graphic icons that need to follow my lines of text.

I have one line with a twitter graphic and text address

and

one with a Facebook graphic and test address.

So, thank you so very much for the script!
Reply With Quote
  #7  
Old May 13th, 2010, 05:06 PM
JulieP JulieP is offline
Junior Community Member
 
Join Date: Aug 2009
Posts: 11
Default Re: Moving lines up if one line is blank

Hi Again Dan,

Don't take this the wrong way but I thought you would like to know that I tried your code and it returned blank lines but the lines did not move up. I will try the alternate solution in the morning. I want you to know I really do appreciate your time and assistance greatly! This is what I am working on. They want each line to move up from the bottom when one is blank but they also want to maintain the same space between the top section and bottom section.

Reply With Quote
  #8  
Old May 14th, 2010, 07:16 AM
JulieP JulieP is offline
Junior Community Member
 
Join Date: Aug 2009
Posts: 11
Question Re: Moving lines up if one line is blank

Below is my code for suppressing the icon graphic for the twitter address. Would a possible solution be to first find the current x,y of my twitadr variable and then place the icon graphic (twitter) next to the twitadr variable? This is all I really need to do. All the text works correctly. I just need to move the graphics with the text.


Code:
 
var TwitGraphic = CreateResource(Field("twitter"), "graphic", true);
if(Field("twitadr") == "") {
   return NullResource;
    }
else return  Resource("twitter.pdf");
This is what currently happens if the office number is blank:

Reply With Quote
  #9  
Old May 14th, 2010, 07:59 AM
esmith's Avatar
esmith esmith is offline
Senior Contributor
 
Join Date: Oct 2008
Location: Charlotte, NC
Posts: 869
Default Re: Moving lines up if one line is blank

You should be incorporating your graphic in the text frame as an inline graphic rather than in a separate graphic frame. Do a search in the forums for "inline graphic" for a slew of posts on how to do this.
__________________
Eric Smith
Content Developer
Classic
FP 9.3.6, MAC OSX 10.9.4, Acrobat 11.0.09
Reply With Quote
  #10  
Old May 14th, 2010, 08:25 AM
JulieP JulieP is offline
Junior Community Member
 
Join Date: Aug 2009
Posts: 11
Default Re: Moving lines up if one line is blank

Fantastic! Will do. Thanks for the heads up! Julie
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 04:19 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.