Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

If I set the title field to Read only (since I will calculate it based upon other values) in the ListAdded Event handler, when i open up a form for creating a new item i get an error.

Event handler..

public override void ListAdded(SPListEventProperties properties)
   {
       //Set Title column as READ ONLY

       SPField f = properties.List.Fields[new Guid("{fa564e0f-0c70-4ab9-b863-0177e6ddd247}")];
       f.ReadOnlyField = true;
       f.Update();
       base.ListAdded(properties);
   }

This works, as the Title field no longer shows up in the new item form, but when debugging in get a JS error , and I think it is due to the form trying to focus that field. If instead i set INHERIT=FALSE on the content type, title dissappears fro mthe form, but so does another site column i aded ot the content type, Assigned To. Assigned To is still in the custom content type, but it does not show up on the new form when adding an item to the list.

Any ideas on how ot get the Assigned To field back in the form?

share|improve this question
    
Since Title is by default required field maybe this is reason for JS error. Try to add f.Required = false;. I had manually created one task list with Title field to be ReadOnly. No errors everything is working as expected. –  Vedran Rasol Aug 6 '11 at 23:02

2 Answers 2

up vote 1 down vote accepted

There are properties on SPField meant to specifically control when a field is presented to the user. You may also want to set a DefaultValue and turn off EnforceUniqueValues:

        SPField f = properties.List.Fields[SPBuiltInFieldId.Title];
        f.ShowInNewForm = false;
        f.ShowInEditForm = false;
        f.EnforceUniqueValues = false;
        f.DefaultValue = "some default value so required check(s) don't fail";
        f.Update();
share|improve this answer

To extend on what Vedran suggested, the following should be equivalent to setting the Title column's settings to Hidden (Will not appear in forms) when editing the list's content type in the UI:

SPField f = properties.List.Fields[SPBuiltInFieldId.Title];
f.Required = false;
f.Hidden = true;
f.Update();
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.