0

I am looking to update a google form drop down list using concatenation of 3 columns (arrays in reference to the code). The output looks correct but the alignment is still not right even after padding individual strings. Here is my sample code :

function updateForm1(){

  var items = [ ["apple", "organic", "101"], ['banana', 'small', '102'], ['pomegranate', 'medium', '1']];
  var itemnames = ['apple' , 'banana', 'pomegranate'];
  var description = ['organic' , 'small', 'medium'];
  var ordercode = ['101', '102', '1'];
  var l1 = itemnames.reduce(function (a, b) { return a.length > b.length ? a : b; }).length;
  var l2 = description.reduce(function (a, b) { return a.length > b.length ? a : b; }).length;
  var l3 = ordercode.reduce(function (a, b) { return a.length > b.length ? a : b; }).length;


  var dropdownlist = [];
  for (var i =0 ; i < items.length; i++)
  {
    if(items[i][0].length > 0) {
      items[i][0] = items[i][0].padEnd(l1,"*"); 

    }
    else 
      items[i][0] = "".padEnd(l1,"*"); 
    if(items[i][1].length > 0) {
      items[i][1] = items[i][1].padEnd(l2,"*");

    }
    else 
      items[i][1] = "".padEnd(l2,"*"); 
    if(items[i][2].length > 0) {
      items[i][2] = items[i][2].padEnd(l3,"*");

    }
    else 
      items[i][2] = "".padEnd(l3,"*"); 
    dropdownlist[i] = items[i][0] + " | " + items[i][1] + " | " + items[i][2];
    Logger.log(dropdownlist[i]);

  }


}

Log :

[20-06-19 12:12:47:845 IST] apple****** | organic | 101
[20-06-19 12:12:47:848 IST] banana***** | small** | 102
[20-06-19 12:12:47:849 IST] pomegranate | medium* | 1**

But when I update the form or see the log, values don't seem to be aligned.See pic below. How can I make the dropdown values appear aligned to columns?enter image description here

PriyankaJ
  • 339
  • 4
  • 19
  • I'm not sure I understand your issue. The width of each string would depend on the width of each character, so it would depend on what exact characters are there for each string and which font is used. You could measure the width of each string by rendering those on an HTML and doing [this](https://stackoverflow.com/a/118251/10612011) with the expected font and add characters to each string based on that, but I don't think your project is supposed to have a client-side. Anyway, why is it necessary to get this aligned? – Iamblichus Jun 19 '20 at 10:54
  • You've understood my problem well. And I acknowledge each character will have its own width, but I am looking to display these values in a dropdown list. So if they are aligned they look better – PriyankaJ Jun 19 '20 at 11:07

0 Answers0