Wednesday, September 20, 2006

Yesterday I came across a small problem in CRM I needed to disable all fields in a form except one o_O. So this is what I came up with:

I put this in my form_load event

Since I am a lazy programmer is used a loop :D

var type = 'hidden+text+select-one+checkbox+textarea+radio';
for (i=0;i <crmform.all.length;i++){
if(type.indexOf(crmForm.all[i].type) != -1){
//disable all fields except new_SomeField
crmForm.all[i].disabled= (crmForm.all[i].id != 'new_SomeField');
//Disable lookup fields manually
crmForm.all.ownerid.disabled = true;
crmForm.all.preferredserviceid.disabled = true;
crmForm.all.preferredequipmentid.disabled = true;
crmForm.all.preferredsystemuserid.disabled = true;

For the future maybe use an array containing all
the fields you want to disable / leave enabled.