2

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?

1
  • 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. Commented Aug 6, 2011 at 23:02

2 Answers 2

2

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();
2

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();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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