Hi Mike,
I need to say that to meet the requirement the actual logic is much more complicated that just changing a CSS on the frontend:
Since the field color need to be changed on file saved to repository, it must save to backend which fields have been changed on frontend; and in case user changed the field value back to lookup result, frontend need to compare lookup results with current values on field value change.
Here is a piece of code that meet the above logic. You need to add a single line field with class 'SaveChangedFields' on the form for saving changed fields. I tested it work for lookup filling single field and filling new row, but can't guarantee it work on your form since field type/lookup rules might be different:
$(document).ready(function(){
var changeFieldList = [];
if ($('input[name=IsLocked]').val()=='True') {
//Form is read-only, read value from SaveChangedFields
var saveChangedFields = $('.SaveChangedFields .cf-field').text().split(',');
if (saveChangedFields.length > 0) {
_.each(saveChangedFields, function(field){
$("#"+field.replace('(','\\(').replace(')','\\)')).css('background','#ffff99');
});
}
} else {
//Form is not read-only
$('#form1').on('change', CheckFieldUpdate);
}
function CheckFieldUpdate(e) {
var targetFieldId = $(e.target).attr('id');
var targetFieldTopId = parseInt(targetFieldId.match(/^Field(\d+)/)[1]);
var lookupCache = _.last(_.filter(LF.lookup.cache, ['id', targetFieldTopId]));
if (lookupCache) {
//Lookup has single value or no value on this field
if (lookupCache.value.length <= 1) {
CheckIfChanged($(e.target),lookupCache.value.length == 1 ? lookupCache.value[0] : "");
} else {
if (lookupCache.expandColTable) {
//Lookup fill as new rows
var targetFieldSubId = parseInt(targetFieldId.match(/^Field\d+\((\d+)\)/)[1]);
CheckIfChanged($(e.target),lookupCache.value.length >= targetFieldSubId ? lookupCache.value[targetFieldSubId-1] : "");
}
}
}
}
function CheckIfChanged(element, lookupVal) {
var targetFieldId = element.attr('id');
if (lookupVal != element.val()) {
element.css('background','#ffff99');
if (changeFieldList.indexOf(targetFieldId) == -1) {
changeFieldList.push(targetFieldId);
$('.SaveChangedFields input').val(changeFieldList.join(','));
}
} else {
element.css('background','#ffffff');
if (changeFieldList.indexOf(targetFieldId) > -1) {
_.remove(changeFieldList, function(n){return n == targetFieldId});
$('.SaveChangedFields input').val(changeFieldList.join(','));
}
}
}
});