Friday, November 21, 2008

Disabling all fields on a form...dynamically

There have been a number of times where I have had clients request that when certain fields are set one way or another they would actually like to disable the entire form. Or they want to disable the entire form except for a status field, or something like that. For some clients this was a HUGE pain in the neck because every field would have to be done manually. And whenever a new field was added if the script wasn't updated then that new field would be updateable while everything else would stay locked down.

Well, I found this code posted by Michael Höhne from Stunnware and it was exactly what I've been trying to do.

for (var index in crmForm.all) {
var control = crmForm.all[index];
if (control.req && (control.Disabled != null)) {
control.Disabled = true;

That will disable them all. Pretty sweet. Then if they want to leave a status field or something enabled just manually enable them afterwards:

crmForm.all.new_status.Disabled = true;

And you're all set.

David Fronk
Dynamic Methods Inc.


Saritha said...

Slight correction, to enable one field manually, you need to set the property Disabled to false, not true.

crmForm.all.new_status.Disabled = false;

Dynamic Methods said...


You are correct, thanks for catching that. I have since updated my post to read correctly.

Thanks again,

David Fronk
Dynamic Methods Inc.

Anonymous said...

Hi David,

It gave me a big help.

Thank in Advance,

Dave Berry said...

Ping back from

Post a Comment