Jump to content

NEED HELP....inserting text


strido

Recommended Posts

I tried searching for "text rule" or something, but :eek: there's alot of returns, and not a lot of help...

 

The issue is, I have two fields, a phone and an email. The actual text in the paragraph is as follows:

 

......contact me at (555) 555-5555 or someschmuck@duh.com.

 

Well, naturally the client apparently forgets to put in the email in their data, so it returns this:

 

......contact me at (555) 555-5555 or .

 

That looks pretty silly. Currently the "or" is typeset into the textbox. I'd like to put it in a rule so that when this happens, the "or" will be omitted when I check "suppress when empty".

 

Now that I think about it I'll probably need a rule for CustomLine01 (the phone number) because next time that'll be the one they omit.

 

#@(*#(

Link to comment
Share on other sites

Give this a shot, put in your Field names:

 

if (Field("Email") == "")

return "contact me at " + (Field("Phone")+ ".");

else

return "contact me at " + (Field("Phone")+ " or " + (Field("Email")));

Link to comment
Share on other sites

You're right, you're going to want to account for all instances of "blanks" in the data so in addition to the email addresses you also want to have a rule for the phone numbers. Or you can put them all into one rule like this:

 

var result= "";

result += (Field("Phone") != "" || Field("Email") != "") ? "Feel free to contact me at " : "";
result += (Field("Phone") != "" ) ? Field("Phone") : "";
result += (Field("Phone") != "" && Field("Email") != "") ? " or " : "";
result += (Field("Email") != "" ) ? Field("Email") : "" ;

return result;

 

This way if both both fields are left blank, the entire sentence will not print. However, if just phone is populated it will return "Feel free to contact me at [phone]" and if just email is populated, it will return "Fee free to contact me at .

Link to comment
Share on other sites

This way if both both fields are left blank, the entire sentence will not print. However, if just phone is populated it will return "Feel free to contact me at [phone]" and if just email is populated, it will return "Fee free to contact me at .

More generalized:

function removeEmptyItems(inArray)
{
 var newArray = new Array();
 for (var i = 0; i < inArray.length; i++)
 {
     if (inArray[i])
       newArray.push(inArray[i]);
 }
 return newArray;
}

var arr = removeEmptyItems([Field("Phone"), Field("Email")]);

return arr.length ? "Feel free to contact me at " + arr.join(" or ") : "";

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...