Hey Everyone! does anyone know how I can change te...
# suitescript
s
Hey Everyone! does anyone know how I can change text color of a custom field on view and edit mode?
👀 1
t
use inlinehtml field type
💯 2
l
If you’re looking for more flexible on field style, maybe you can consider using Client script, but most of case just like @Tyn Guardian say, inlinehtml is enough
j
I’ve done this in a super hacky unsupported DOM-manipulatey way before as the following example illustrates:
Copy code
function 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;');
				
							
		}		
					
	}
	
}
👍 2