Jump to content

Center Justify based on field value


Recommended Posts

Hello All,

 

I want to be able to change how a line or paragraph is being justified based on the value of a specific field. I'm pretty new to both FP and JavaScript so I'm still figuring out syntax for these things. Here is what I am trying to do.

 

if(Field("Name") != "")
     return "Centered Text" + Field("Name");
return "Left Justified Text" + Field("Name");

 

I thought I may be able to use the "<span>" tags and I looked through the reference guide, but I didn't see anything on this specifically. I really appreciate any help offered.

Link to comment
Share on other sites

Hello All,

 

I want to be able to change how a line or paragraph is being justified based on the value of a specific field. I'm pretty new to both FP and JavaScript so I'm still figuring out syntax for these things. Here is what I am trying to do.

 

if(Field("Name") != "")
     return "Centered Text" + Field("Name");
return "Left Justified Text" + Field("Name");

 

I thought I may be able to use the "<span>" tags and I looked through the reference guide, but I didn't see anything on this specifically. I really appreciate any help offered.

 

Try something like this. Be sure to check Treat returned strings as tagged text.

 

if(Field("Name") != "")
     return '<p br="false" quad="C">' + Field("Name");
return '<p br="false" quad="L">' + Field("Name");

Edited by David Miller
Link to comment
Share on other sites

If the "Name" field is empty, you want to return some left-justified text and the "Name" field? That seems odd.

 

Either way, the tag you're looking for is the paragraph tag (page 42 of the TagsRefGuide.pdf documentation). The "quad" attribute will allow you to adjust the alignment with values of "L," "R,", "C," and "J" (left, right, centered, and justified respectively). Keep in mind that a paragraph tag by default starts a new paragraph (adding a line break) so if you want to avoid a line break, use the 'br' attribute and set it to false.

 

So in your situation, you just want to determine if the alignment should be a "C" or an "L" based on the value of the "Name" field:

var align = Field("Name") ? 'C' : 'L';
var str   = Field("Name") ? 'Centered Text' + Field("Name") : 'Left Justified Text';
return '<p br=false quad=' + align + '>' + str;

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