You are viewing limited content. For full access, please sign in.

Question

Question

Table reversed

asked on January 12, 2017

I have some javascript (below) that creates a recap table and stores references to some fields to be updated later when processing answer changes in other tables. This all works fine and displays as expected on the form and submission page.

However once the Save to Repository task runs the table is flipped. Does anyone know where to look for an issue like this? My CSS (below) is minimal so far, so I don't think that is the issue.

function createRecapTable() {
  var tbl = document.createElement('table');
  tbl.style.width = '100%';
  var head = tbl.insertRow();
  var cat = head.insertCell();
  cat.appendChild(document.createTextNode('Section'));
  $(cat).attr('style', 'font-weight:bold; background-color: Gainsboro !important; height: 25px;');
  var allow = head.insertCell();
  allow.appendChild(document.createTextNode('Allowed'));
  $(allow).attr('style', 'text-align: center; font-weight:bold; background-color: Gainsboro !important; height: 25px;');
  allow.style.width = '70px';
  var earn = head.insertCell();
  earn.appendChild(document.createTextNode('Earned'));
  $(earn).attr('style', 'text-align: center; font-weight:bold; background-color: Gainsboro !important; height: 25px;');
  earn.style.width = '70px';
  var percent = head.insertCell();
  percent.appendChild(document.createTextNode('Percent'));
  $(percent).attr('style', 'text-align: center; font-weight:bold; background-color: Gainsboro !important; height: 25px;');
  percent.style.width = '70px';

  var sections = Object.keys(section_groupings);
  for(var i = 0; i < sections.length; i++) {
    var section = sections[i];
    var tr = tbl.insertRow();
    var name = tr.insertCell();
    name.appendChild(document.createTextNode(section));
    var allowed = tr.insertCell();
    allowed.appendChild(document.createTextNode('0'));
    $(allowed).attr('style', 'text-align: center;');
    section_groupings[section]['recap_allowed'] = $(allowed);
    var earned = tr.insertCell();
    earned.appendChild(document.createTextNode('0'));
    $(earned).attr('style', 'text-align: center;');
    section_groupings[section]['recap_earned'] = $(earned);
    var percentage = tr.insertCell();
    percentage.appendChild(document.createTextNode('0.00'));
    section_groupings[section]['recap_percentage'] = $(percentage);

    group = section_groupings[section]['group'];
    last = section_groupings[section]['last'];

    if(last) {
      groups[group] = {};
      var sum = tbl.insertRow();
      var grp_name = sum.insertCell();
      grp_name.appendChild(document.createTextNode(group));
      $(grp_name).attr('style','font-weight:bold; background-color: Cornsilk !important; height: 25px; width: 70px;');
      var grp_allowed = sum.insertCell();
      grp_allowed.appendChild(document.createTextNode('0'));
      $(grp_allowed).attr('style','text-align: center; font-weight:bold; background-color: Cornsilk !important; height: 25px; width: 70px;');
      grp_allowed.style.width = '70px';
      groups[group]['recap_allowed'] = $(grp_allowed);
      var grp_earned = sum.insertCell();
      grp_earned.appendChild(document.createTextNode('0'));
      $(grp_earned).attr('style','text-align: center; font-weight:bold; background-color: Cornsilk !important; height: 25px; width: 70px;');
      grp_earned.style.width = '70px';
      groups[group]['recap_earned'] = $(grp_earned);
      var grp_percentage = sum.insertCell();
      grp_percentage.appendChild(document.createTextNode('0.00'));
      $(grp_percentage).attr('style','text-align: center; font-weight:bold; background-color: Cornsilk !important; height: 25px; width: 70px;');
      grp_percentage.style.width = '70px';
      groups[group]['recap_percentage'] = $(grp_percentage);
    }
  }
  console.log(tbl);
  $(tbl).insertBefore($('#q4'));
}
/* remove background coloring from selection */
.form-focused { background-color: white; }

/* align/bold inputs */
.right_align input { text-align: right; }
.center_align input { text-align: center; }
.center_align div div { text-align: center; }
.bold_input input { font-weight: bold; }

/* correct sizing of xl objects */
.cf-xlarge {width: 100%;}

/* layout header as table*/
.total_score, .director {display: inline-block; width: 50%;}
.audit_period, .dm {display: inline-block; width: 50%;}
.site_id, .manager {display: inline-block; width: 50%;}
.store_location, .deli_person {display: inline-block; width: 50%;}
.store_format, .auditor {display: inline-block; width: 50%;}
.inline > .cf-label {width: 30% !important;}
.inline > .cf-field {width: 70% !important;}
 
/* hide audit table headers */
#q1, #q7, #q11, .hidden {display:none;} 

/* setup cig audit results */
.cig_totals_1 {display: inline-block; width: 33%;}
.cig_totals_1 > .cf-label {width: 50% !important;}
.cig_totals_1 > .cf-field {width: 50% !important;}
.cig_totals_2 {display: inline-block; width: 33%;}
.cig_totals_2 > .cf-label {width: 50% !important;}
.cig_totals_2 > .cf-field {width: 50% !important;}

/* setup lot audit results */
.lot_totals_1 {display: inline-block; width: 33%;}
.lot_totals_1 > .cf-label {width: 50% !important;}
.lot_totals_1 > .cf-field {width: 50% !important;}
.lot_totals_2 {display: inline-block; width: 33%;}
.lot_totals_2 > .cf-label {width: 50% !important;}
.lot_totals_2 > .cf-field {width: 50% !important;}

/* setup cash audit results */
.cash_totals_1 {display: inline-block; width: 33%;}
.cash_totals_1 > .cf-label {width: 50% !important;}
.cash_totals_1 > .cf-field {width: 50% !important;}
.cash_totals_2 {display: inline-block; width: 50%;}
.cash_totals_2 > .cf-label {width: 50% !important;}
.cash_totals_2 > .cf-field {width: 50% !important;}

#q4 {page-break-after: always;}
#q4 {page-break-before: always;}
#q29 {page-break-before: always;}
#q55 {page-break-before: always;}
#q81 {page-break-before: always;}
#q89 {page-break-before: always;}
#q96 {page-break-before: always;}

 

0 0

Answer

SELECTED ANSWER
replied on January 17, 2017

It isn't the most elegant solution as the submission page is flipped but since I care most about the version saved to the repository I've added more Javascript to flip the table when on the submission page. Figured I'd leave this here in case anyone else came across this issue.

  if(submission_mode) {
    $('tbody',tbl).each(function(elem,index){
      var arr = $.makeArray($('tr',this).detach());
      arr.reverse();
      $.each(arr, function(){
        var arr2 = $.makeArray($('td',this).detach());
        arr2.reverse();
        $(this).append(arr2);
      });
      $(this).append(arr);
    });
  }

 

0 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.