Jump to content

Indent text if target field has a value

Recommended Posts

Hi all.


I am an absolute beginner with JavaScript. I have been reading and exploring trying to find the answers I need but have run into a roadblock.


I am looking to create a rule which will use firstLineIndent to indent the text in a frame if a target field has a value.


I am working on a business card project where the text aligns as follows:


P: 123-456-7890___C: 123-456-7890

F: 123-456-7890___E: abcdefg@hij.com

(underscores being space between the fields, as I can't figure out how to illustrate that here)


Simple enough. If not for the little wrinkle that some individuals have extensions added to their phone numbers. In those cases, the Cell and Email text needs to move to the right about a half inch to accommodate the extension, making it look more like this:


P: 123-456-7890 ext 1111____C: 123-456-7890

F: 123-456-7890____________E: abcdefg@hij.com


My thought is to create a rule, which could be applied to the Cell and Email frames, which invokes a firstLineIndent if the Ext field has a value. I've gotten this far...


if (Field("Ext") > "0")





So yeah...no idea how of the syntax required to do what I want. Or am I way out to lunch on this altogether?

Link to comment
Share on other sites

Hopefully this will set you in the right direction. Basically it sets up the tabstops as a variable based on if the extension number is filled out or not. I hardcoded in the phone numbers just so you can see how this would work.


var tabval = "0;12000,Left";
var extpfx = "";

if (Field("Ext").length > 0)
   tabval = "0;16000,Left";
   extpfx = " ext ";

return '<p br="false" tabstops=' + tabval + '>' + "P: 123-456-7890" + extpfx + Field("Ext") + '<t>' + "C: 123-456-7890" + '<br>' + "F: 123-456-7890" + '<t>' + "E: abcdefg@hij.com";

Link to comment
Share on other sites

Okay, so perhaps not perfectly clear... :o


Inserting that rule (and applying the appropriate fields) returns the following in preview:


<p br="false" tabstops=0;16000,Left>P: 123-456-7890 ext 3042<t>C: 123-456-7890<br>F: 123-456-7890<t>E:abcdefg@hij.com


Note: It did pick up my actual phone, cell, fax and email fields. I just didn't want to display them here.


So I'm wondering if I've missed a step. Why is it returning the literal code?

Link to comment
Share on other sites

If you want to keep them in separate frames you would need to create a rule for each of the two numbers on the right.


var indent = "0";

if (Field("Ext").length > 0)
   indent = "7200";

return '<p br="false" findent=' + indent + '>' + Field("field name");


This sets the indent only if there is a value for the phone extension.

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.

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