Spec:
CRMField.Disable() - Disable Field
CRMField.Enable() - Enable Field
CRMField.HideCell() - Hide Cell ( field + label )
CRMField.ShowCell() - Show Cell
CRMField.HideRow() - Hide Entire Row
CRMField.ShowRow() - Show Entire Row
CRMField.Required() - Make Field Required *
CRMField.Level() - Get Field Required level
CRMField.NotRequired() - Make Field Not Required
CRMField.Changed() - Returns whether the Field was changed since it was loaded
CRMField.IsEmpty() - Checks whether the Field is null or empty("")
CRMField.Alert() - Helper function - Alerts the Field DataValue
CRMField.OnChange( OnFieldChangeEvent ) – Attaches a function to the Field OnChange Event
CRMField.ReLabel( "New label" ) - Change Field label (HTML)
CRMField.InitValue - Holds the Field Initial Value
CRMField.LastValue - Holds the Field Last value before it was changed
CRMField.First() - Revert to the Field Initial Value
CRMField.Last() - Revert to the Field Last Value
Paste the CrmField class inside the entity onload event or global.js (unsupported).
function CrmField( fieldId )
{
var crmField = this;
crmField.Id = fieldId;
if( crmField.Id == null || crmField.Id == "" ) return;
crmField.Field = document.getElementById(fieldId);
if( this.Field == null ) return;
crmField.InitValue = crmField.Field.DataValue;
crmField.LastValue = "";
crmField.Cell = document.getElementById(this.Field.id + "_d");
crmField.Label = document.getElementById(this.Field.id + "_c");
crmField.Row = crmField.Cell.parentElement;
crmField.Disable = function(){ crmField.Field.Disabled = true; }
crmField.Enable = function(){ crmField.Field.Disabled = false; }
crmField.HideCell = function(){
crmField.Field.style.visibility = "hidden";
crmField.Cell.style.visibility = "hidden";
crmField.Label.style.visibility = "hidden";
}
crmField.HideRow = function(){ crmField.Row.style.display = "none"; }
crmField.ShowCell = function(){
crmField.Field.style.visibility = "visible";
crmField.Cell.style.visibility = "visible";
crmField.Label.style.visibility = "visible";
}
crmField.ShowRow = function() { crmField.Row.style.display = "inline"; }
crmField.Required = function() { crmForm.SetFieldReqLevel(crmField.Id,true); }
crmField.NotRequired = function(){ crmForm.SetFieldReqLevel(crmField.Id,false); }
crmField.Level = function() { return crmField.Field.RequiredLevel; }
crmField.Changed = function() { return crmField.Field.IsDirty(); }
crmField.IsEmpty = function() { return (crmField.Field.DataValue == null); }
crmField.Alert = function() { alert(crmField.Field.DataValue); }
crmField.Last = function() { crmField.Field.DataValue = crmField.LastValue; }
crmField.First = function() { crmField.Field.DataValue = crmField.InitValue; }
crmField.OnChange = function(f){ crmField.Field.attachEvent("onchange",f); }
crmField.ReLabel = function(txt){ crmField.Label.innerHTML = txt; }
}
//Test - contact form
var firstname;
function OnCrmPageLoad()
{
firstname = new CrmField("firstname");
firstname.ReLabel("Given Name");
firstname.OnChange( OnFirstnameChange )
}
function OnFirstnameChange()
{
firstname.Alert();
}
OnCrmPageLoad();
Feel free to comment.