Jump to content

Bullet list - suppress


mmorse

Recommended Posts

Hello -

I've got a bullet list that, when empty, should suppress. My issue is that my rule enters a bullet on the first entry without the need for a return. Because the bullet exists, the field is never technically empty. If i use a rule that requires a return to create a bullet, I'm left with an empty line at the top, before the list begins.

 

Any thoughts much appreciated.

 

Rule:

 

outstr = "";

itemName = "ulOne";

if(itemName != "ulOne"){

return outstr += '      ' + Field(itemName);

}else if(outstr == null){

return itemName.suppress;

}else{

return outstr += '     • ' + Field(itemName).replace(/<p>/g, "<br>     • ");

 

 

};

 

 

Thank you!

Matt

Link to comment
Share on other sites

Alot of the code that you've written isn't doing anything. For example:

outstr = ""; 
itemName = "ulOne";

You've set the global variable "outstr" to be an empty string. Then you set the global variable "itemName" to be "ulOne" – which appears to be the name of the field you're using later in the rule. That part makes sense.

if(itemName != "ulOne"){

Then you check to see if the 'itemName' variable (which you just set to "ulOne") is not equal to "ulOne." Anything in that conditional will not be executed so it's kind of pointless to put it there.

else if(outstr == null){
return itemName.suppress;

You're checking to see if "outstr" is null when you just set its value to an empty string. If you wanted to check to see if anything had been added to that variable, you should do something like:

else if (outstr == "")
// or: else if (!outstr)

It doesn't really matter though because ".suppress" is not a function of a string ("itemName") and it would throw you an error.

 

You probably just want to check if the field is empty before adding a bullet to it like this:

var bullet = '     • ';
var itemName = 'ulOne';
var result = "";

if (Field(itemName)){
   result = bullet + Field(itemName);
}

return result;

 

Or to apply a bullet to the start of every paragraph (more details here):

var bullet = '     • ';
var itemName = Field("ulOne");
return itemName.split("<p>").filter(String).map(function(s){return bullet + s;}).join("<p>");

Link to comment
Share on other sites

That works...thank you!

 

My only remaining issue is in the formatting of the subsequent lines in the multi-line list item. Is there anyway to format those so they fall in line with the first line, instead of defaulting back to the left margin?

 

Thank you!

Link to comment
Share on other sites

That works...thank you!

 

My only remaining issue is in the formatting of the subsequent lines in the multi-line list item. Is there anyway to format those so they fall in line with the first line, instead of defaulting back to the left margin?

 

Thank you!

 

What works? What code did you use? I'm not really sure what you're asking but the last block of code I posted (see below) adds 5 non-breaking spaces and a bullet to the start of every line so they shouldn't be "defaulting back to the left margin." Unless, of course, the new lines in that field are being delimited by something other than a paragraph tag ("<p>"). But either way it's really hard to say without seeing what your data looks like.

 

Or to apply a bullet to the start of every paragraph (more details here):

var bullet = '     • ';
var itemName = Field("ulOne");
return itemName.split("<p>").filter(String).map(function(s){return bullet + s;}).join("<p>");

Link to comment
Share on other sites

Of course....here is the rule...

 

var bullet = '     • ';

var itemName = Field("ulOne");

return itemName.split("<p>").filter(String).map(function(s){return bullet + s;}).join("<p>");

 

The second line of the list item falls to the left margin, instead of lining up with the left margin position of the first line.

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