After working through many suggestions from ChatGPT, I have found the following to update the field value in a particular view and add a status badge in the view as well. I am concatenating the data into a text formula field from 1x text formula field and 1x multiple choice field (that is updated via workflow). This uses CSS and JS and I cannot comment on performance as the app is still in production…
Here is the JS…
//
/ Status Badge Update to Oceans Job Ref Details Field_320 /
//
$(document).on(‘knack-view-render.any’, function (event, view, data) {
var cells = document.querySelectorAll(‘#’ + view.key + ’ .field_320 .kn-detail-body’);
cells.forEach(function(cell) {
var fieldValue = cell.textContent.trim();
var fieldValueParts = fieldValue.split(’ ‘);
var oceansRefNumber = fieldValueParts.shift();
var status = fieldValueParts.join(’ ');
var codeOutput;
if (status) {
codeOutput = '<span class="job-info"><h5 class="mb-0 mr-10 font-20">Job #: ' + oceansRefNumber + '</h5></span> <span class="badge status-text badge-status-' + status.toLowerCase().replace(' ', '-') + '">' + status + '</span>';
cell.innerHTML = codeOutput;
}
});
});
Here is the CSS…
/STATUS BADGES/
.job-info {
display: inline-flex;
align-items: center;
vertical-align: text-top;
}
.status-text {
font-family: Arial, sans-serif;
font-style: italic !important;
font-weight: bold !important;
vertical-align: middle;
padding: 3px 6px;
border-radius: 3px;
}
.mb-0 {
margin-bottom: 0;
}
.badge-status-load-scheduled {
background-color: #f2c7f3;
color: #c400d9;
margin-left: 5px;
font-size: 70%;
}
.badge-status-load-active {
background-color: #c8f2d4;
color: #267a4b;
margin-left: 5px;
font-size: 70%;
}
.badge-status-load-inactive {
background-color: #f8c7c7;
color: #7f0000;
margin-left: 5px;
font-size: 70%;
}
.badge-status-in-storage {
background-color: #fff5b3;
color: #e6b800;
margin-left: 5px;
font-size: 70%;
}
.badge-status-job-complete {
background-color: #a8b9ff;
color: #0033a0;
margin-left: 5px;
font-size: 70%;
}
.badge-status-accounting-review {
background-color: #f9dab8;
color: #a65c00;
margin-left: 5px;
font-size: 70%;
}
.badge-status-invoiced {
background-color: #b7b6b5;
color: #000000;
margin-left: 5px;
font-size: 70%;
}
Hope this helps!