Jump to content

Formatting with conjunction exceptions


tonias81

Recommended Posts

Hello all, I am looking to have a department title change to TitleCase but not conjunctions (to, for, and, the, but, etc.) but I end up getting user input "office of the president" or "OFFICE OF THE PRESIDENT" to translate to "Office Of The President". If I fix one, I lose the other. I also need to have the "&" translate as "and" with an exception to the following: "Dining & Catering", Parent & Family Connections", and "Department of Technology Leadership & Innovation". I believe this code snippet works for that fix. Any thoughts about the title case conjunctions issue?

 

var DeptName = ToTitleCase(Field("department"));

DeptName = DeptName.replace("&","and").replace("Dining and Catering","Dining & Catering")

.replace("Parent and Family Connections","Parent & Family Connections")

.replace("Departmen of Technology Leadership and Innovation","Department of Technology Leadership & Innovation");

 

return DeptName

 

Thanks,

Tony Hayden

Xerox

Link to comment
Share on other sites

I would do this:

var DeptName = ToTitleCase(Field("department"));

var exceptions = ["to", "for", "of", "and", "the", "but"];
for (var e in exceptions)
{
   var exception = exceptions[e];
   DeptName = DeptName.replace(new RegExp("\\b" + exception + "\\b", "gi"), exception);
}

switch (DeptName)
{
   case "Dining & Catering":
   case "Parent & Family Connections":
   case "Department of Technology Leadership & Innovation":
       break;

   default:
       DeptName = DeptName.replace("&", "and");
       break;
}

return DeptName;

Or maybe:

var DeptName = ToTitleCase(Field("department"));

DeptName = DeptName.replace(/\b(to|for|of|and|the|but)\b/gi, function(s){return s.toLowerCase()});

var leaveAmpersands =
[
   "Dining & Catering",
   "Parent & Family Connections",
   "Department of Technology Leadership & Innovation",
];

if (leaveAmpersands.indexOf(leaveAmpersands) < 0)
   DeptName = DeptName.replace("&", "and");

return DeptName;

Link to comment
Share on other sites

Thanks Dan, the top code version worked but not the bottom one. I also included a script to remove all "special characters" as well.

 

here is the code snippet:

 

var DeptName = ToTitleCase(Field("department"));

 

var exceptions = [ "a" , "an" , "the" , "for" , "and" , "at" , "by" , "of" , "on" , "to" , "with" ];

for (var e in exceptions)

{

var exception = exceptions[e];

DeptName = DeptName.replace(new RegExp("\\b" + exception + "\\b", "gi"), exception);

}

 

var specialChars = "!@#$^%*()+=-[]\/{}|:<>?,.";

 

for (var i = 0; i < specialChars.length; i++) {

DeptName = DeptName.replace(new RegExp("\\" + specialChars, "gi"), "");

}

 

switch (DeptName)

{

case "Dining & Catering":

case "Parent & Family Connections":

case "Department of Technology Leadership & Innovation":

break;

 

default:

DeptName = DeptName.replace("&", "and").replace("Dining and Catering", "Dining & Catering")

.replace("Parent and Family Connections", "Parent & Family Connections")

.replace("Department of Technology Leadership and Innovation", "Department of Technology Leadership & Innovation") ;

break;

}

 

return DeptName

 

 

Again, thanks so much Dan!

 

--------------

Tony Hayden

Xerox

Link to comment
Share on other sites

so everything seems to work but realized that once the template processes, it return Br in the department. (see screenshot)

 

I've tried enabling/disabling the Treat returned strings as tagged text function with no luck. I do not see anything in the code that would allow/not allow the break. Thoughts

screenshot.jpg.2690f3ca0b70fc7a37e1b4757be62add.jpg

Link to comment
Share on other sites

Thanks Dan, the top code version worked but not the bottom one.

Can you please be more specific about exactly what didn't work?

I also included a script to remove all "special characters" as well.

Why? What's wrong with those characters? In what context?

so everything seems to work but realized that once the template processes, it return Br in the department. (see screenshot)

What web application is that screenshot from? Is it DSF?

 

That's not really a FusionPro VDP template issue as much as it's an issue specific to that web app.

 

It looks like the web app is building up a tagged markup data file, with <br> tags where you type in line breaks. But your rule is removing the "<" and ">" from the tags, which is changing the <br> tag to just "br" as you see in the output. Again, why do you think you need to remove those "special" characters?

 

Also, why do you need a multi-line text box for the input from that data field? and why are you typing in those line breaks at all? Why not just enter the department name, without typing the line breaks, and let FusionPro typeset the text for you?

I've tried enabling/disabling the Treat returned strings as tagged text function with no luck. I do not see anything in the code that would allow/not allow the break. Thoughts

I think what you need to do is talk to the people who make that web app and see if you can use just a single-line field there. Or don't type any line breaks. Either that, or you need to account for that web app using tagged markup input, by changing the first line of your rule to this:

var DeptName = ToTitleCase(TaggedDataField("department"));

And removing your code that gets rid of those "special" characters, because some of those are needed for the tagged markup. And yes, you need to check the "Treat returned strings as tagged text" box.

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