Home > CRM, Development Teams > Read-only and Disabled Fields

Read-only and Disabled Fields

Excellent explanation of setting read-only and disabled fields in CRM via JavaScript:

ReadOnly and Disabled Fields – Ryan Farley’s Blog

Let’s look at a few of the common types of fields:

Text and Numeric Fields (nvarchar, ntext, float, int, and money)

These types of fields are easy enough to work with. These render as a simple HTML input tags inside a table cell. The input control renders with an ID that matches the schema name. So for a field with a schema name of ‘new_textfield’, you can do either of the following to set it as readonly or disable it:

// set it as readonly 
crmForm.all.new_textfield.readOnly = true;
// OR set it as disabled
crmForm.all.new_textfield.disabled = true;

Picklist Fields

These render as HTML select tags. You can set these as readonly and disabled the same as you can with text fields (see above).

Lookups

Things might seem complicated here, but for this purpose they are not. The control itselfs renders as a DIV and an IMG inside a table. The DIV shows the selected lookup value. This renders as a DIV to disallow any possible way to edit the value (all that is needed is the ID of the “looked-up” item anyway, the text is just for display). The IMG, of course, is the magnifying lookup image that you click to get the lookup list. Since the DIV is already uneditable by the user, all you need to worry about is the IMG. Luckily, the image will have the schema name as it’s ID value so no need to dig for the info of what to change. For a lookup named ‘AccountLookup’ you would simply do the following:



// disable lookup field
crmForm.all.new_accountlookupid.disabled = true;


Categories: CRM, Development Teams
  1. Dylan
    April 4, 2011 at 4:53 PM

    Hello,

    I am pretty new to CRM and am in need of some help. I want to write this code above for an onChange event. I would like to be able to state:

    If new_setappointmnet equals no (bit field)

    crmForm.all.new_appointmenttype.disabled = true;

    If new_setappointment equals yes

    crmForm.all.new_appointmenttype.disabled = false;

    Can anyone help me write this code?

    And I believe the code goes in the onChange event of new_appointmenttype, is that correct?

    Thank you for your help.

    Dylan

  2. ravenrip
    April 4, 2011 at 8:11 PM

    That is correct. If this was a checkbox then you might want to enter a new function in the onLoad event of the form with this following code structure:

    crmForm.all.new_setappointmnet.onclick = function()
    {
    if ( crmForm.all.new_setappointmnet.checked )
    {
    crmForm.all.new_appointmenttype.disabled = true ;
    }
    else
    {
    crmForm.all.new_appointmenttype.disabled = false;
    }
    }

    Also look at this page, has some great stuff if your just getting started:
    http://www.stunnware.com/crm2/topic.aspx?id=JS12

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: