Login / Register  search  syndication  about

          Ryan Farley's Blog

Ryan Farley on .NET Development with a focus on CRM Development for SalesLogix

ReadOnly and Disabled Fields

When you need to set fields disabled or readonly at runtime, you need to keep in mind the type of field you use. Setting a HTML input field is a simple line of Javascript, however, the type of CRM field you've chosen will have an impact on exact items you need to change at runtime. I personally like the look of disabled over readonly. A disabled control will show it's value greyed, indicating to the user that they cannot modify it's contents. A readonly field appears normal. The user only finds out that they cannot change it's value until they attempt to do so.

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;

 

One thing to point out here is that readonly doesn't work on an IMG tag. You can only set it disabled.

Date Fields

Date fields are a little bit more tricky. As you know, the date field will render as an INPUT and IMG (for the calendar popup) inside a table. In this case, the shema name will be used as the ID for the table containing the INPUT and IMG tags, not the ID for the INPUT as you might expect. The IMG tag will render as the schema name ending in 'img'. So for a date field with schema name 'new_datefield', the IMG will have the ID of 'new_datefieldimg' and will be inside a table named 'new_datefield'. We first need to disable the IMG, just as we did for Lookup fields (see above). We can't disable the 'new_datefield' object, since that refers to the table container. We need to disable the IMG, which is named 'new_datefieldimg'.  Also, you can go the extra mile and change the image to reflect the disabled look.

// disable date field
crmForm.all.new_datefieldimg.disabled = true;
crmForm.all.new_datefieldimg.src = '/_imgs/btn_dis_cal.gif';

 

You can always flip the image for lookups to the disabled one as well (which is a good idea IMO).

Bit Fields

For bit fields you have 3 options for display, radio buttons, a checkbox, or a picklist. For the third option, we've already discussed that (See picklist fields above). For display as a checkbox or as radio buttons your method will be the same. It is a simple matter of setting it as disabled, such as in this example using a bit field named 'new_bitfield'.

// disable bit field (as radio buttons, checkbox, or list)
crmForm.all.new_bitfield.disabled = true;

 

What's This?
Bookmark and Share

About Ryan Farley

   Ryan Farley is the Director of Development for Customer FX Corporation and the creator of slxdeveloper.com.

Don't miss Ryan's Git for the SalesLogix Developer series!



Related Content
   Ping a Remote Server Using VBScript
At times you might build a customization in the SalesLogix LAN client that relies on networked resources.
Posted on May 19, 2008 by Ryan Farley to Ryan Farley's Blog
 
   KnowledgeSync
Business Activity Monitoring (BAM) has become the way that many companies are generating real return from
Content from Partner Products Section
 
   Working with CRM 3.0 Sample Chapter Available
Mike Snyder and Jim Steger of Sonoma Partners have announced the availability of the sample chaper on Wor
Posted on Feb 28, 2006 by Ryan Farley to Ryan Farley's Blog
 
   Easier Navigation with Browser Tabs
A common complaint I hear those who are more used to the modality of Windows-based CRM applications is th
Posted on Feb 24, 2006 by Ryan Farley to Ryan Farley's Blog
 
   Getting XSD Schema for CRM Entities
I posted before about the CRM Metadata Browser that can be used to see and document the various CRM entit
Posted on Feb 17, 2006 by Ryan Farley to Ryan Farley's Blog
 
Comments

 

eric wassberg said:

This is EXACTLY what I have been looking for. Thank you
March 7, 2006 4:32 PM
 

Jeffrey Jones said:

Hello All,

I am having an issue with the disabled form type.

I can get the picklists to show as read only. I cannot get the ntext, nvarchar, int or money fields to show up readOnly.

Here is a sample of my logic:

if( formType == 3 || formType == 4 )
{
crmForm.all.new_someMoneyIntNtextNvarcharField.disabled = false;
crmForm.all.new_someMoneyIntNtextNvarcharField.readOnly = true;
}

I am 'sure' I have done this correctly.

Thanks.
March 8, 2006 10:19 AM
 

Ronald Lemmen said:

Hi,

Good article! I dislike the readOnly feature as well because it confuses the user. When using disabled, then also when tabbing it skips that field.

Jeffrey, and others,
Make sure that you do not(!) end your script with a comment. This will cause the script to not work.

Ronald Lemmen
Avanade Netherlands
March 17, 2006 6:37 AM
 

Jeffry van de Vuurst said:

Just wondering, why not use the CRM field "Disabled" (Capital D) property? It's described in the SDK.

E.g. when you say crmForm.all.new_MyDateField.Disabled = true; it automatically takes care of changing the image for the disabled look.

Jeffry van de Vuurst
CWR Mobility

March 18, 2006 1:39 PM
 

Michael Dodd said:

I was wondering if you could disable fields based on certain users...

The scenario:

As a User Security Role, the "Customer Service" User is the only one allowed to update Address and Telephone number, Fax, etc. fields on an Account.

Other users can update other fields, so when a User opens the account form (OnLoad) only users with "Customer Service" roles will be able to edit the Address, etc. fields.

How could the script be written to look at a user role?
April 10, 2006 11:03 AM
 

Matthew said:

Is there anyway to iterate over all the fields on the form? I need to set ALL fields as read-only/disabled but don't want to have to write out each field name, plus, it leaves it open to problems if fields are added in later.

Thanks!
June 22, 2006 9:16 AM
 

Sam Psmith said:

I am having to overwrite the fullname field in lead using javascript on a form and am setting the value correctly but it is being replaced with lastname,firstname after the save. I think it is something to do with readonly on fullname - but forcesubmit still does not clear the problem. So i am still only halfway there on readonly fields.,.....
June 30, 2006 4:29 AM
 

Sujeesh said:

Hi,
I want to make the img tag readonly or disabled.. Plz help me
August 30, 2006 12:06 AM
 

RexW said:

Re: setting a field to disabled based on a security role: I have done this by creating an aspx page that generates a short piece of xml e.g. <result>true</result> if the current user belongs to a certain security role (there is a sample in the SDK to extract all security roles for a user). then on the crm form, I disable the field by default, and then use a small script that uses the ActiveXObject("Microsoft.XMLDOM") to open the xml from the abovementioned page and check if the result is true, if so, I enable the field.
This entire solution is basically a variation of the duplicate check example in the SDK (sdk samples\fullsample\duplicatedetection)
November 23, 2006 12:20 PM
 

Ved said:

Nice article. Was what I was looking for.
March 16, 2007 8:12 AM
 

Ahammedullah Reja said:

Nice article. Thanks
March 22, 2007 11:13 PM
 

Steve Jones said:

I am looking for a code that will make an input field read-only only if they select a certain radio button. Can you help?
May 10, 2007 7:31 PM
 

Phumlo said:

Good one, how do i enable a field at runtime. I have tried this code but it doesnt work. crmForm.all.field_name.readOnly = false;
June 7, 2007 7:10 AM
 

Tariq said:

You can easily check whether the user logged into the crm is having a particular role by using the function currentUserHasRole ('ROLE NAME').
This function will return a boolean value.
July 20, 2007 6:54 AM
 

kontrol said:

For Phumlo:
go for Disable from Security roles, and Enable with:
crmForm.all.new_field.Disabled = false;
it works.
August 7, 2007 5:03 AM
 

Suresh ChinnaThambi said:

When i try to disable the datetime field, I'm not able to acheive the desired result.


crmForm.all.new_datefield.disabled= true;

but even after executing the code date field remains to be enabled.

if any one knows the reason put me a mail(protocol1983@gmail.com)

Regards,
Suresh
August 28, 2007 4:22 AM
 

Kamal said:

thanks guys that was very helpfull as I needed to disable a date field and i wasn't able to until i used the capital D for Disabled.
March 11, 2008 10:55 AM
 

Niamh said:

I have a readonly  total field on my CRM form. I am updating this total using javascript. However when I click to save the form, the value does not write to the database because the field is readonly. I have tried to enable to field using javascript under the on save event on the form but this does not work. Does anyone have any other ideas on how this could be done?

June 10, 2008 6:55 AM
 

geek said:

its working in ie7 but its not working in ie6 and mozilla

July 2, 2008 1:22 AM
 

Ajay said:

Nice article.

By the way the right syntax to disable the date field is below -

crmForm.all.new_datefield.Disabled = true;

crmForm.all.new_datefieldimg.src = '/_imgs/btn_dis_cal.gif';

Please note that "disabled" has to be with a capital "D".

And we have to reference the field 'new_datefield' object not IMG.

July 9, 2008 11:54 AM
 

Rohit Mishra said:

Nice Article

But I want to disable one form tab. how i make it

July 11, 2008 1:09 AM
 

Saurin said:

In order to assign value to and SAVE a read only field by javascript, write crmForm.all.<field>.ForceSubmit = true;

after crmForm.all.<field>.DataValue="some value";

July 23, 2008 6:17 AM
 

Shiva said:

This code helped me.

Thanks

Shiva

August 8, 2008 4:09 AM
 

Carlos Roweder Nass said:

Great tips... Thanks

Carlos

www.netzenos.com.br

October 3, 2008 10:07 AM
 

RJ said:

I need to hide a section on a crm form.  The section contains a single read-only field.  I'm using the standard parentElement.style.display = 'none' syntax.  It doesn't work.  Ideas?  Sorry for the tangent.

December 5, 2008 12:51 AM
 

Raja said:

This code helped me,

Thanks a lot

April 7, 2009 11:16 AM
 

Manoj Talwar said:

To disable the time portion of date field, the code is:

crmForm.all.<datefield>.all.time.disabled();

and to enable it back:

crmForm.all.<datefield>.all.time.enabled();

Does anybody know how to disable/enable the date portion?

May 27, 2009 4:16 AM
 

Manoj Talwar said:

Sorry, read its as follows:

crmForm.all.<datefield>.all.time.disable();

and to enable it back:

crmForm.all.<datefield>.all.time.enable();

May 27, 2009 5:38 AM
 

Geraldine said:

I need to enable a disabled datetime field. I have tried enabling it thru "crmForm.all.<new_datefield>.Disabled = false;". The datepicker is available for date pick. But the selected date that display on the date field is disabled. It does not allow manual entry into the field. Any idea how to resolve this? Thanks

June 29, 2009 5:13 AM
 

Jim Bob said:

@Geraldine...

The sample shows 2 lines;

- The first line actually disables the control.

- The second Line makes it look disabled.

Reversing this would require 2 lines also.

// disable date field

crmForm.all.new_datefieldimg.disabled = true;

crmForm.all.new_datefieldimg.src = '/_imgs/btn_dis_cal.gif';

August 26, 2009 10:43 PM
 

Vimal said:

Hi,

How to disable the entire tabpage.

I am able to hide the tabpapage.

But I want to disable the entire tabpage.

The following code is not working.

crmForm.all.tab1Tab.Disabled = true;

Please help me how disable the entire Tab. So the user will not be allowed to modify any value in that Tab.

September 1, 2009 5:41 AM
 

KAmaldeep said:

Thanks.. It helped me disable the lookup fields..

December 31, 2009 12:36 AM
 

prashant mir@je said:

i have used the same code for disable text field on onload event of form,but it didn't work,plz help me out.

i am trying it virtual CRM machine,is there any security level in virtual CRM ,so taht i can't change it..

March 23, 2010 1:11 AM

Leave a Comment

(required)  
(optional)
(required)  
Add
All contents Copyright © 2010 Customer FX Corporation
Customer FX Corporation
2324 University Avenue West, Suite 115
Saint Paul, Minnesota 55114
Tel: 800.728.5783

  Follow @CustomerFX on twitter
Follow the best news, tips, and articles
  Subscribe to Customer FX on youtube
Watch SalesLogix tutorial videos from Customer FX
Login / Register