Jump to content

rule for bullets between text


Jeff Berry

Recommended Posts

I thought somebody might be able to use this sometime. It adds bullets between fields. I used it for our agent credentials on business cards.

 

var string1 = Field("Cred1")
var string2 = Field("Cred1") + " " + '<p br="false" override="true" lindent="900" tabstops="0;900,Left"><color Name="Black">•<t>' + " " + Field("Cred2")
var string3 = Field("Cred1") + " " + '<p br="false" override="true" lindent="900" tabstops="0;900,Left"><color Name="Black">•<t>' + " " + Field("Cred2") + " " + '<p br="false" override="true" lindent="900" tabstops="0;900,Left"><color Name="Black">•<t>' + " " + Field("Cred3")
var string4 = Field("Cred1") + " " + '<p br="false" override="true" lindent="900" tabstops="0;900,Left"><color Name="Black">•<t>' + " " + Field("Cred2") + " " + '<p br="false" override="true" lindent="900" tabstops="0;900,Left"><color Name="Black">•<t>' + " " + Field("Cred3") + " " + '<p br="false" override="true" lindent="900" tabstops="0;900,Left"><color Name="Black">•<t>' + " " + Field("Cred4")
var string5 = Field("Cred1") + " " + '<p br="false" override="true" lindent="900" tabstops="0;900,Left"><color Name="Black">•<t>' + " " + Field("Cred2") + " " + '<p br="false" override="true" lindent="900" tabstops="0;900,Left"><color Name="Black">•<t>' + " " + Field("Cred3") + " " + '<p br="false" override="true" lindent="900" tabstops="0;900,Left"><color Name="Black">•<t>' + " " + Field("Cred4") + " " + '<p br="false" override="true" lindent="900" tabstops="0;900,Left"><color Name="Black">•<t>' + " " + Field("Cred5")
var string6 = Field("Cred1") + " " + '<p br="false" override="true" lindent="900" tabstops="0;900,Left"><color Name="Black">•<t>' + " " + Field("Cred2") + " " + '<p br="false" override="true" lindent="900" tabstops="0;900,Left"><color Name="Black">•<t>' + " " + Field("Cred3") + " " + '<p br="false" override="true" lindent="900" tabstops="0;900,Left"><color Name="Black">•<t>' + " " + Field("Cred4") + " " + '<p br="false" override="true" lindent="900" tabstops="0;900,Left"><color Name="Black">•<t>' + " " + Field("Cred5") + " " + '<p br="false" override="true" lindent="900" tabstops="0;900,Left"><color Name="Black">•<t>' + " " + Field("Cred6")
var string7 = Field("Cred1") + " " + '<p br="false" override="true" lindent="900" tabstops="0;900,Left"><color Name="Black">•<t>' + " " + Field("Cred2") + " " + '<p br="false" override="true" lindent="900" tabstops="0;900,Left"><color Name="Black">•<t>' + " " + Field("Cred3") + " " + '<p br="false" override="true" lindent="900" tabstops="0;900,Left"><color Name="Black">•<t>' + " " + Field("Cred4") + " " + '<p br="false" override="true" lindent="900" tabstops="0;900,Left"><color Name="Black">•<t>' + " " + Field("Cred5") + " " + '<p br="false" override="true" lindent="900" tabstops="0;900,Left"><color Name="Black">•<t>' + " " + Field("Cred6") + " " + '<p br="false" override="true" lindent="900" tabstops="0;900,Left"><color Name="Black">•<t>' + " " + Field("Cred7")


if (Field("Cred1") != "" && Field("Cred2") == "" && Field("Cred3") == "" && Field("Cred4") == "" && Field("Cred5") == "" && Field("Cred6") == "" && Field("Cred7") == "")
return string1

if (Field("Cred1") != "" && Field("Cred2") != "" && Field("Cred3") == "" && Field("Cred4") == "" && Field("Cred5") == "" && Field("Cred6") == "" && Field("Cred7") == "")
return string2

if (Field("Cred1") != "" && Field("Cred2") != "" && Field("Cred3") != "" && Field("Cred4") == "" && Field("Cred5") == "" && Field("Cred6") == "" && Field("Cred7") == "")
return string3

if (Field("Cred1") != "" && Field("Cred2") != "" && Field("Cred3") != "" && Field("Cred4") != "" && Field("Cred5") == "" && Field("Cred6") == "" && Field("Cred7") == "")
return string4

if (Field("Cred1") != "" && Field("Cred2") != "" && Field("Cred3") != "" && Field("Cred4") != "" && Field("Cred5") != "" && Field("Cred6") == "" && Field("Cred7") == "")
return string5

if (Field("Cred1") != "" && Field("Cred2") != "" && Field("Cred3") != "" && Field("Cred4") != "" && Field("Cred5") != "" && Field("Cred6") != "" && Field("Cred7") == "")
return string6

if (Field("Cred1") != "" && Field("Cred2") != "" && Field("Cred3") != "" && Field("Cred4") != "" && Field("Cred5") != "" && Field("Cred6") != "" && Field("Cred7") != "")
return string7

//else
return ""

Link to comment
Share on other sites

You could just do this instead:

var MyArray = [];
for (var i = 1; i <= 7; i++)
{
   if (Field("Cred" + i))
       MyArray.push(TaggedTextFromRaw(Field("Cred" + i)));
}
return MyArray.join("&[size=2]#[/size]32;•&[size=2]#[/size]32;");

Here's a more generalized solution, where you can change the list of fields in the first line:

var MyArray = [ Field("Name"), Field("Phone"), Field("Email") ];
var NonEmpty = [];
for (var i in MyArray)
{
   if (MyArray[i])
       NonEmpty.push(TaggedTextFromRaw(MyArray[i]));
}
return NonEmpty.join("&[size=2]#[/size]32;•&[size=2]#[/size]32;");

Link to comment
Share on other sites

Wow Dan you broke down my mess of code. You are the JS king :)

 

I was just reading about arrays over the weekend and was thinking of ways that I could use them. This is a great example. I'm rapidly building my knowledge of JS and 90% of that is due this forum. Thanks for all you do!

 

Jeff

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...