In CRM 2011 we have all these jQuery stuff to play with, so I have created a generic function to make all the required labels which are not filled in Red. Then when they are filled in, they switch back to black.
Here you can see the function, first field is filled, and is black. Second is yet to be filled, hence Red.
This is simpler then you might think, however the SDK examples are a bit too simple to have this support. Since I want to make my function generic. I don’t want to have to add my function to every field that is required. This is how I did it:
if (typeof (stq) == "undefined") { stq = {}; } stq.SaveCheck = { AttachOnLoad: function () { var attributes = Xrm.Page.data.entity.attributes.get(function (attribute, index) { return (attribute.getRequiredLevel() == "required") }); for (var i in attributes) { var attribute = attributes[i]; attribute.addOnChange(stq.SaveCheck.attributeChanged); attribute.fireOnChange(); } }, attributeChanged: function (context) { var name = context.getEventSource().getName(); var field = Xrm.Page.getAttribute(name); if (field.getValue() == null) stq.SaveCheck.setLabelColor(name, "Red"); else stq.SaveCheck.setLabelColor(name, "Black"); }, setLabelColor: function (fieldName, color) { $("#" + fieldName + "_c > label[for=" + fieldName + "]").css("color", color); } };
do you know how to change the background color of a text field (not label, but field)?
it’s just a minor change:
exchange
$(“#” + fieldName + “_c > label[for=" + fieldName + "]“).css(“color”, color);
with
$(“#” + fieldName).css(“background”, color);