View Single Post
  #14  
Old July 27th, 2016, 08:11 AM
tou tou is offline
Regular Contributor
 
Join Date: Oct 2015
Posts: 107
Default Re: Table / Copyfitting for 1 to 6 fields

Looks like you'll have to code 2 rules....

Rule # 1 - line1
Rule # 2 - line2


line1 (var a,b,c,d,e,f are for testing only and should point to your field - I've used static strings for testing)
Code:
var a="A"
var b=""
var c="C"
var d="D"
var e="E"
var f="F"

var fields = [a,b,c,d,e,f].filter(String);

var myTable = new FPTable;

if (fields.length == 1)
    var cols = 1
    else if (fields.length == 2)
    var cols = 2
    else if (fields.length == 3)
    var cols = 3
    else if (fields.length == 4)
    var cols = 2
    else if (fields.length == 5)
    var cols = 3
    else 
    var cols = 3

if (cols == 1) {
   myTable.AddColumns(32328);
   var myRow = myTable.AddRow();
   myTable.HAlign = "Center";
   myRow.Cells[0].HAlign = "Center"; 
   myRow.Cells[0].Content = fields[0];
} else if (cols == 2) {
   myTable.AddColumns(16164, 16164);
   var myRow = myTable.AddRow();
   myTable.HAlign = "Center";
   myRow.Cells[0].HAlign = "Center"; 
   myRow.Cells[1].HAlign = "Center"; 
   myRow.Cells[0].Content = fields[0];
   myRow.Cells[1].Content = fields[1];
} else {
   myTable.AddColumns(10776, 10776, 10776);
   var myRow = myTable.AddRow();
   myTable.HAlign = "Center";
   myRow.Cells[0].HAlign = "Center"; 
   myRow.Cells[1].HAlign = "Center"; 
   myRow.Cells[2].HAlign = "Center"; 
   myRow.Cells[0].Content = fields[0];
   myRow.Cells[1].Content = fields[1];
   myRow.Cells[2].Content = fields[2];
}

return myTable.MakeTags();
line 2 (var a,b,c,d,e,f are for testing only and should point to your field - I've used static strings for testing)
Code:
var a="A"
var b=""
var c="C"
var d="D"
var e="E"
var f="F"

var fields = [a,b,c,d,e,f].filter(String);

var myTable = new FPTable;

if (fields.length == 1)
    var cols = 1
    else if (fields.length == 2)
    var cols = 2
    else if (fields.length == 3)
    var cols = 3
    else if (fields.length == 4)
    var cols = 2
    else if (fields.length == 5)
    var cols = 2
    else 
    var cols = 3

if (cols == 1) {
} else if (cols == 2) {
   myTable.AddColumns(16164, 16164);
   var myRow = myTable.AddRow();
   myTable.HAlign = "Center";
   myRow.Cells[0].HAlign = "Center"; 
   myRow.Cells[1].HAlign = "Center";
   if (fields.length == 4) {  
      myRow.Cells[0].Content = fields[2];
      myRow.Cells[1].Content = fields[3];
   } else if (fields.length == 5) {
      myRow.Cells[0].Content = fields[3];
      myRow.Cells[1].Content = fields[4];
   } 
} else {
   if (fields.length > 3) {  
      myTable.AddColumns(10776, 10776, 10776);
      var myRow = myTable.AddRow();
      myTable.HAlign = "Center";
      myRow.Cells[0].HAlign = "Center"; 
      myRow.Cells[1].HAlign = "Center"; 
      myRow.Cells[2].HAlign = "Center"; 
      myRow.Cells[0].Content = fields[3];
      myRow.Cells[1].Content = fields[4];
      myRow.Cells[2].Content = fields[5];
   }
}

return myTable.MakeTags();
In your text box, stack the two variables on top of each other.

Last edited by tou; July 27th, 2016 at 08:16 AM..
Reply With Quote