strido Posted August 3, 2011 Share Posted August 3, 2011 I tried searching for "text rule" or something, but 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. #@(*#( Quote Link to comment Share on other sites More sharing options...
Kal Posted August 3, 2011 Share Posted August 3, 2011 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"))); Quote Link to comment Share on other sites More sharing options...
step Posted August 3, 2011 Share Posted August 3, 2011 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 . Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted August 3, 2011 Share Posted August 3, 2011 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 ") : ""; Quote Link to comment Share on other sites More sharing options...
strido Posted August 3, 2011 Author Share Posted August 3, 2011 You guys are the bomb..... Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.