MarcomCentral (PTI) and FusionPro User Communities

MarcomCentral (PTI) and FusionPro User Communities (http://forums.pti.com/index.php)
-   The JavaScript Library (http://forums.pti.com/forumdisplay.php?f=23)
-   -   How to escape special characters in a table? (http://forums.pti.com/showthread.php?t=5401)

geeool September 20th, 2019 03:36 PM

How to escape special characters in a table?
 
1 Attachment(s)
Hi,

I have a business card where my client wants to use a carrot '>' symbol between the label and the phone number (see attached screen capture for reference). I decided to use a table for laying out the numbers because the top number will sometimes have an extension, so it needs to float.

As I'm building my table and testing it, I'm finding that the carrot '>' symbol won't display. I've tried escaping it, but that hasn't worked.
Code:

var office = 'O '+'/\(>\)/ '+' '+Rule("OfficePhoneRULE")+' Ext.'+Field("Ext.");
Full table code below. Any suggestions?

Code:

var table = new FPTable;
var NoR = 3// NoR = number of rows (one less than actual)
    // Setting the table width of the columns
table.AddColumns(6000, 1000, 10000);
table.AddRows(4);  // Adds the number of rows to the table.

for(a=0;a<=NoR;a++)  // Counter for building the rows (rows 0 thru 3)
{
    for(b=0;b<1;b++)  // Counter for building the cells (cell 0 )
    {
        table.Rows[a].Cells[b].SetBorders("Thin", "Red", "Top", "Bottom", "Left", "Right"); // Adds red line around table cell
        table.Rows[a].Cells[b].Margins = new FPTableMargins;  // This needs to be set every time the margins change
        table.Rows[a].Cells[b].Margins.Top = 55;  // I had to have a larger Top Margin to make the text look centered between the top and bottom borders
        table.Rows[a].Cells[b].Margins.Bottom = 55;
        table.Rows[a].Cells[b].Margins.Left = 200;
        table.Rows[a].Cells[b].Margins.Right = 200;
        table.Rows[a].Cells[b].Font = "Knockout HTF31-JuniorMiddlewt";  // This sets the font for the first cell, the second is set at the text frame.
        table.Rows[a].Cells[b].TextColor = "Black";  // This sets the font for the first cell, the second is set at the text frame.
    }
        for(c=1;c<2;c++)  // Counter for building the cells (cell 1)
    {
        table.Rows[a].Cells[c].SetBorders("Thin", "Red", "Top", "Bottom", "Left", "Right"); // Adds red line around table cell
        table.Rows[a].Cells[c].Margins = new FPTableMargins;  // This needs to be set every time the margins change
        table.Rows[a].Cells[c].Margins.Top = 55;  // I had to have a larger Top Margin to make the text look centered between the top and bottom borders
        table.Rows[a].Cells[c].Margins.Bottom = 55;
        table.Rows[a].Cells[c].Margins.Left = 200;
        table.Rows[a].Cells[c].Margins.Right = 200;
    }
            for(d=2;d<3;d++)  // Counter for building the cells (cell 2)
    {
            table.Rows[a].Cells[d].SetBorders("Thin", "Red", "Top", "Bottom", "Left", "Right"); // Adds red line around table cell
            table.Rows[a].Cells[d].Margins = new FPTableMargins;  // This needs to be set every time the margins change
            table.Rows[a].Cells[d].Margins.Top = 55;  // I had to have a larger Top Margin to make the text look centered between the top and bottom borders
            table.Rows[a].Cells[d].Margins.Bottom = 55;
            table.Rows[a].Cells[d].Margins.Left = 200;
            table.Rows[a].Cells[d].Margins.Right = 200;
    }
}

for(i=0;i<=4;i++) {
//var prep_field_num = i+1;
//var prep_field = 'Instruction'+prep_field_num;
var ext = Field("Ext.");
var office = 'O '+'/\(>\)/ '+' '+Rule("OfficePhoneRULE")+' Ext.'+Field("Ext.");
var store = Field("S");
var mobile = Field("M");
var fax = Field("F");
    if (ext != "") {
        table.Rows[0].Cells[0].Margins = new FPTableMargins;  // This needs to be set every time the margins change
        table.Rows[0].Cells[0].Margins.Top = 65;  // I had to have a larger Top Margin to make the text look centered between the top and bottom borders
        table.Rows[0].Cells[0].Margins.Bottom = 40;
        table.Rows[0].Cells[0].Margins.Left = 200;
        table.Rows[0].Cells[0].Margins.Right = 200;
        table.Rows[0].Cells[0].Font = "Knockout HTF31-JuniorMiddlewt";
        table.Rows[0].Cells[0].PointSize= "8";
        table.Rows[0].Cells[0].HStraddle = 3;
        table.Rows[0].Cells[0].Content = office;
        }
           
    if (store != "") { // if field contains *h2* it will be a headline
        table.Rows[1].Cells[1].Margins = new FPTableMargins;  // This needs to be set every time the margins change
        table.Rows[1].Cells[1].Margins.Top = 65;  // I had to have a larger Top Margin to make the text look centered between the top and bottom borders
        table.Rows[1].Cells[1].Margins.Bottom = 40;
        table.Rows[1].Cells[1].Margins.Left = 200;
        table.Rows[1].Cells[1].Margins.Right = 200;
        table.Rows[1].Cells[1].Font = "Knockout HTF31-JuniorMiddlewt";
        table.Rows[1].Cells[1].PointSize= "8";
        table.Rows[1].Cells[1].Content = store; //removing the *h2* in front of the field content
        }   


    else { // When an empty field is encountered, break loop and build table
            break;
                }
        }   


table = table.MakeTags();  // This is required
return table;  // This is required

Thanks for the help.

Dan Korn September 20th, 2019 04:19 PM

Re: How to escape special characters in a table?
 
As you can see if you click Validate in the rule, the table that's being returned is a bunch of HTML/XML-like tagged markup, so that means you have to follow tagged markup guidelines for certain characters which have special meanings, such as angle brackets <> to denote a tag, single- and double-quotes, and ampersands. You could use entities such as &lt; to represent such characters literally in tagged markup, but that can get tricky. Fortunately, there's a function that can do all the necessary entity replacements for you, called TaggedTextFromRaw. So you can just do this:
Code:

var office = TaggedTextFromRaw('O > ' + Rule("OfficePhoneRULE") + ' Ext.' + Field("Ext."));

geeool September 23rd, 2019 01:06 PM

Re: How to escape special characters in a table?
 
Thanks Dan, that worked!


All times are GMT -7. The time now is 07:36 AM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.