Creating Summary Table with HTML and Calculated Fields
-
I followed the directions on this post, but I’m having trouble getting a Checkbox field to display all ticked choices.
Here is the setup:
Assign choices to Checkbox Field (fieldname359 – this is working, example:
function setCheckboxAddonSelections() {
// Initialize arrays for labels and values
let texts = [];
let values = [];
if (fieldname381 > 0) {
texts.push(CONCATENATE('<span class="pchoice-label">Backing</span><span class="pchoice-value-contain"><span class="pchoice-listmfg">', formatCurrency(fieldname381|v), '</span><span class="pchoice-listmfg">', formatCurrency(fieldname443|v), '</span><span class="pchoice-promo">', formatCurrency(fieldname444|v), '</span></span>'));
values.push(1);
}
etc. etc. etc.Checkbox Field Settings (fieldname359):
- Merge ticked-up options is checked in settings
- Value to submit is set to Choice Value in settings
HTML Field html (fieldname1262):
<div class="summary-here"></div>
<div class="summary-here-also"></div>AUX Calculated Field (NOT WORKING)
(function() {
var summary = '<table>' +
'<thead><tr>' +
IF(fieldname359, '<th>Component</th>', '') +
IF(fieldname359, '<th>Price</th>', '') +
'</tr></thead>' +
'<tbody>' +
IF(fieldname359|v == 1,
'<tr>' +
'<td>Backing</td>' +
'<td>' + fieldname381|v + '</td>' +
'</tr>',
'') +
IF(fieldname359|v == 2,
'<tr>' +
'<td>Accent</td>' +
'<td>' + fieldname432|v + '</td>' +
'</tr>',
'') +
'</tbody>' +
'</table>';
jQuery('.summary-here-also').html(summary);
return summary;
})();At one point, I was able to get a single row to display using a version of code for a radio button, that code is below.
Long story, short… I want any field that is ticked in checkbox field to display a product name and a price. However; 1) The checkbox choices are generated dynamically, 2) The Text/Label in the checkboxes field that is assigned is done so dynamically with custom formatting.
(function() {
// Add styles
var styles =<br> table {<br> width: 100%;<br> border-collapse: collapse;<br> margin: 20px 0;<br> font-size: 16px;<br> text-align: left;<br> }<br> th, td {<br> border: 1px solid #ddd;<br> padding: 8px;<br> }<br> th {<br> background-color: #f4f4f4;<br> font-weight: bold;<br> }<br> .list-column {<br> text-align: right; /* Float-like effect for List column */<br> }<br> tbody tr:nth-child(even) {<br> background-color: #f9f9f9;<br> }<br> tbody tr:hover {<br> background-color: #f1f1f1;<br> }<br>;
var styleSheet = document.createElement("style");
styleSheet.type = "text/css";
styleSheet.innerText = styles;
document.head.appendChild(styleSheet);
// Generate the table
var summary = '<table>' +
// First header row
'<thead><tr>' +
IF(fieldname122, '<th>Product Line</th>', '') +
IF(fieldname122, '<th class="list-column">List</th>', '') +
'</tr></thead>' +
// First data row
'<tbody>' +
IF(fieldname122, '<tr>' +
// Product Line
IF(fieldname122|v == 1, '<td>Everyday</td>', '') +
IF(fieldname122|v == 2, '<td>Classic</td>', '') +
IF(fieldname122|v == 3, '<td>Regency</td>', '') +
IF(fieldname122|v == 4, '<td>Brio Everyday</td>', '') +
IF(fieldname122|v == 5, '<td>Brio Classic</td>', '') +
// List Price
IF(fieldname122|v == 1, '<td class="list-column">' + fieldname123|v + '</td>', '') +
IF(fieldname122|v == 2, '<td class="list-column">' + fieldname126|v + '</td>', '') +
IF(fieldname122|v == 3, '<td class="list-column">' + fieldname129|v + '</td>', '') +
IF(fieldname122|v == 4, '<td class="list-column">' + fieldname132|v + '</td>', '') +
IF(fieldname122|v == 5, '<td class="list-column">' + fieldname135|v + '</td>', '') +
'</tr>', '') +
'</tbody>' +
'</table>';
jQuery('.summary-here').html(summary);
return summary;
})();
The topic ‘Creating Summary Table with HTML and Calculated Fields’ is closed to new replies.