Jump to content

Javascript Works for One Template but not the Other


jefff

Recommended Posts

I have a business card that has a minor alteration to it, I basically copied the template along with the accompanying scripts to create the new one.

 

The only difference between the two templates is instead of having stacked phone/cell numbers they want them to be side-by-side and slide over when either number is missing in the data.

 

Here is the script:

 

if (Field("Phone") == "")

return 'c '+Rule("Cell Dot Rule");

if (Field("Cell") == "")

return 'p '+Rule("Phone Dot Rule");

else

return 'p '+Rule("Phone Dot Rule")+ ' '+'c '+Rule("Cell Dot Rule")

 

Worked for the first template (stacked) but when the data is missing on the phone or cell number all I get is a blank text box on the new template.

 

Is this a scripting issue or Fusion Pro issue?

Link to comment
Share on other sites

No warning or error messages and the script works fine when both phone and cell number are present in data. The blank text box occurs when there is only one phone number or one cell number. Then the text box on the preview is empty.

 

Like I said, it worked fine on the first template when I had the phone and cell number stacked like this:

 

p 217.346.5467

c 217.257.4222

 

It's when I took out the return and made the numbers side-by-side like this that the issue occurs:

 

p 217.346.5467 c 217.257.4222

 

If there is no phone the cell number should slide over flush left but instead....everything disappears and the text box is empty.

Link to comment
Share on other sites

It's kind of impossible to say based on the information you've provided.

 

What is the code for "Cell Dot Rule" and "Phone Dot Rule"? Have you checked the text frame in which you placed the new rule to see if "suppress if containing empty variables" is checked in your new template?

 

In any event, this code should work for you:

return [
 'p ' + Rule("Phone Dot Rule"),
 'c ' + Rule("Cell Dot Rule")
].filter(function(s){ return RawTextFromTagged(s).length > 2 }).join(' ');

Link to comment
Share on other sites

It turns out the "suppress if containing empty variables" was checked.

 

So, now my challenge is the "p" and "c" need to be a customer specified green color and the phone/cell numbers need to be dark gray. What code do I need to add to get the two different colors from the script?

Link to comment
Share on other sites

You still haven't provided any more information about what the rules are doing. How were you changing the color in the first, working template? Check out page 48 of the FusionPro TagsRefGuide.pdf (FusionPro > Documentation > Tags Reference) for information on how to use color tags or search the forum to yield results like this thread or this one.
Link to comment
Share on other sites

OK, followed your advice and applied the color tag to the script. See Below.

 

if (Field("Phone") == "")

return '<color rgb="00B189">c </color>'+Rule("Cell Dot Rule");

if (Field("Cell") == "")

return '<color rgb="00B189">p </color>'+Rule("Phone Dot Rule");

else

return '<color rgb="00B189">p </color>'+Rule("Phone Dot Rule")+ ' '+'<color rgb="00B189">c </color>'+Rule("Cell Dot Rule")

 

According to the Fusion Pro manual the color tag I placed should do exactly what I need but it's still not working.

 

The rules "Phone Dot Rule" and "Cell Dot Rule" are only formatting the number to ensure periods are used instead of hyphens on the phone/cell numbers.

Link to comment
Share on other sites

What do you mean by "still not working?" Initially, you said the code worked in one of your templates. What is the output you're seeing? Are you getting errors when composing? Can you collect and upload your template/data so that it would be to diagnose the issue?
Link to comment
Share on other sites

Collected Template attached.

 

I really don't know how to be any more clear on what I'm trying to achieve.

 

The script works like it should. It removes the phone number when none is present in the data, removes the cell when none is present in the data, and if both numbers are in the data they are there in the preview.

 

The only thing I can not get to work is the tag for the color. The "p" and "c" are green. The actual phone/cell numbers are 80% black.

PremiumRetail_v3.zip

Link to comment
Share on other sites

I really don't know how to be any more clear on what I'm trying to achieve.

 

The script works like it should. It removes the phone number when none is present in the data, removes the cell when none is present in the data, and if both numbers are in the data they are there in the preview.

 

The only thing I can not get to work is the tag for the color. The "p" and "c" are green. The actual phone/cell numbers are 80% black.

Thanks. Perhaps a better description of the problem than just "it doesn't work" would have been, "The letter prefix (c or p) is changing to the color called out in the <color> tag, but the actual phone number after the ending </color> tag is still in that same color." Then someone may have been able to deduce that the original color you're reverting to with the </color> tag (the color of the variable in the text frame) is not actually the color you want. Though actually having the template files made the problem pretty clear, as David notes:

Try changing the color in the actual Text Frame to 80% Black. The "p" and "c" will be green and the phones will be 80% Black.

Yes, but this isn't really a generalized solution, since you actually can't set a percentage of a color directly in the Text Editor, unless you add a new named color to the Colors list and select it. Although the temple in question already has a "DLCOLOR_3" already defined that you can use.

 

But a better solution would probably be just to set all of the colors you want for everything in the rule, so that you don't have to rely on the colors in the text frame, like so:

if (Field("Phone") == "")
   return '<color rgb="00B189">c <color rgb=666666>'+Rule("Cell Dot Rule");
if (Field("Cell") == "")
   return '<color rgb="00B189">p <color rgb=666666>'+Rule("Phone Dot Rule");
//else
   return '<color rgb="00B189">p <color rgb=666666>'+Rule("Phone Dot Rule")+ ' '+'<color rgb="00B189">c <rgb=666666>'+Rule("Cell Dot Rule")

Though since you do already have named colors defined for these, it would be even better to just call those out by name:

if (Field("Phone") == "")
   return '<color name="PMS339c">c <color name="DLCOLOR_3">'+Rule("Cell Dot Rule");
if (Field("Cell") == "")
   return '<color name="PMS339c">p <color name="DLCOLOR_3">'+Rule("Phone Dot Rule");
//else
   return '<color name="PMS339c">p <color name="DLCOLOR_3">'+Rule("Phone Dot Rule")+ ' '+'<color name="PMS339c">c <color name="DLCOLOR_3">'+Rule("Cell Dot Rule")

Using the named colors is especially important if they're spot colors. That will ensure that the spot color is referenced correctly in the output, rather than just a CYMK process color (or, even worse for printing, an RGB process color). But even if you're not using spot colors, it ensures that if you modify the named colors, all the text is change accordingly, without having to edit the RGB or CMYK values in the rule.

 

Of course, that rule can be reduced somewhat:

var result = "";
if (Rule("Phone Dot Rule"))
   result += '<color name="PMS339c">p <color name="DLCOLOR_3">' + Rule("Phone Dot Rule") + " ";
if (Rule("Cell Dot Rule"))
   result += '<color name="PMS339c">c <color name="DLCOLOR_3">' + Rule("Cell Dot Rule");
return Trim(result);

Or more generally:

var numbers = 
{
   p: Rule("Phone Dot Rule"),
   c: Rule("Cell Dot Rule"),
 // add more if needed, e.g.:
 //f: Rule("Fax Dot Rule"),
};

var result = [];
for (var prefix in numbers)
{
   if (numbers[prefix])
       result.push('<color name="PMS339c">' + prefix + ' <color name="DLCOLOR_3">' + numbers[prefix]);
}
return result.join(' ');

Link to comment
Share on other sites

Jeff

Make the text in the text box 80% black. In the rules where you are changing the color, you need to us span for it to only effect the p or c.

See below I edited one of your rules.

 

if (Field("Phone") == "")

return '<span><color rgb="00B189">c </color></span>'+Rule("Cell Dot Rule");

if (Field("Cell") == "")

return '<span><color rgb="00B189">p </color></span>'+Rule("Phone Dot Rule");

else

return '<span><color rgb="00B189">p </color></span>'+Rule("Phone Dot Rule")+ '<    >'+'<color rgb="00B189">c </color>'+Rule("Cell Dot Rule")

Link to comment
Share on other sites

Jeff

Make the text in the text box 80% black. In the rules where you are changing the color, you need to us span for it to only effect the p or c.

See below I edited one of your rules.

 

if (Field("Phone") == "")

return '<span><color rgb="00B189">c </color></span>'+Rule("Cell Dot Rule");

if (Field("Cell") == "")

return '<span><color rgb="00B189">p </color></span>'+Rule("Phone Dot Rule");

else

return '<span><color rgb="00B189">p </color></span>'+Rule("Phone Dot Rule")+ '<******>'+'<color rgb="00B189">c </color>'+Rule("Cell Dot Rule")

That's not really true. The ending </color> tag will revert to the previous color, just like the ending </span> tag will, so having both of them in there is redundant.

 

You could just use <span color="***"> and </span> tags instead of <color name="***"> and </color> tags, but that requires named colors, not RGB or CMYK values (Although you add can named colors with arbitrary RGB or CMYK values, and even spot colors, "on the fly" in rules, and then use those named colors in tags.) At any rate, as I mentioned in my previous post, I recommend using the named colors instead of RGB values.

 

The other option, of course, as I also noted in the previous post, is to just have another <color> tag to call out another specific named color, instead of using the </color> tag to revert to the color set in the text frame.

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