Salman Afzal
08/06/2020, 11:46 PMTyn Guardian
08/07/2020, 12:13 AMLincecum
08/07/2020, 2:28 AMjen
08/07/2020, 5:47 PMjen
08/07/2020, 5:47 PMfunction highlightNonZeroField(field) {
var highlight_element = null;
var field_value = null;
// When in EDIT mode, we simply check that the input exists before seeing if we need
// to highlight it.
if(jQuery('#' + field + '_formattedValue').length) {
// Let's identify what DOM element we would highlight, and get the
// value so that we can compare it with 0.
highlight_element = jQuery('#' + field + '_formattedValue');
field_value = jQuery('#' + field + '_formattedValue').val();
}
// Things are a bit trickier in VIEW mode, since the value isn't in an input field.
// We need to find the <span> that contains the value.
// First, let's check to see if this field even seems to be included in this form.
else if(jQuery('#' + field + '_fs_lbl_uir_label').length) {
// The next <span> contains the value.
highlight_element = jQuery('#' + field + '_fs_lbl_uir_label').next('span');
field_value = highlight_element.html();
}
// If we got an element to check, let's do the check now to see if it should be highlighted.
// Also check that we actually got some value to check (otherwise it is blank).
if(field_value && field_value !== '') {
// Default the style to normal.
highlight_element.css('color','');
// We need to convert the value into a number so that we can compare it with 0.
// It might have dollar signs or percents or other nasty characters.
field_value = parseFloat(field_value.replace(/[,$%]/g,''));
// Is it greater than 0? If so, we need to highlight the field.
if(Math.abs(field_value) > 0) {
// Only way to get IMPORTANT css to be obeyed :(
if(field_value > 0)
highlight_element.attr('style', highlight_element.attr('style') + '; ' + 'color: #19C120 !important;');
else
highlight_element.attr('style', highlight_element.attr('style') + '; ' + 'color: #FF0000 !important;');
}
}
}