Tread carefully when using ReadOnly="TRUE"

SharePoint list definitions (found in SCHEMA.XML) have a nice feature in that you can mark a field as read-only. Just add ReadOnly="TRUE" to your field definition and the end-user will not be able to edit or change it. This is very much like a calculated field which is also read-only but a read-only field allows you to set it. Of course you'll need a way to set it so some custom code is needed but it's a great use of a status field or something through a little C# where you don't want the user changing it (even if they have FrontPage and are site admins).

However adding the ReadOnly attribute also has it's drawbacks. You will not be able to see this field in the UI unless you specifically add it to a view. Adding the ShowInEditForm="TRUE" attribute doesn't do what you might think it would. It's there to force the rendering of fields to the edit form. Any average person would think that once you do this, voila, the field will now show up on the form and since it's read-only you'll get a display of it that nobody can edit right? Wrong. There's no way that I can concievably find that will show a field on either the new form (when adding and item/document) or the edit form. I tried the Viewable="TRUE" attribute but that didn't work either. You can use it on views as it's available there but for forms it just doesn't show up.

Inversely if you add the attribute Hidden="TRUE" to your field definition you'll never see it. Handy for storing stuff in lists that you don't want anyone to get at, but if just remember it's there as it won't show up normally.

1 Comment

  • Nishant Rana has an alternative solution to this problem that works just fine. Check out his article at http://nishantrana.wordpress.com/2009/03/21/adding-a-read-only-field-or-read-only-column-to-sharepoint-list/

Comments have been disabled for this content.