HW90
HW90

Reputation: 1983

Custom Field does not save

I've created a list (sharepoint 2010) that contains a cumstom field. The custom field inherits from SPFieldUser. After I created a new ListItem (webfrontend) and have a look on the elements details the field is empty.

Webfronted NewItemForm Webfronted NewItemForm Webfronted ItemDetailsForm Webfronted ItemDetailsForm Webfronted EditItemForm Webfronted EditItemForm

My Code:

public class Vertreter_FieldType:SPFieldUser
    {
     public Vertreter_FieldType(SPFieldCollection fields, string fieldName)
           : base(fields, fieldName)
       {

       }
        public Vertreter_FieldType(SPFieldCollection fields, string typeName, string fieldName)
            : base(fields, typeName, fieldName)
        {
        }

        public override object GetFieldValue(string value)
        {
            return base.GetFieldValue(value);
        }

        public override string DefaultValue
        {
            get
            {
                return base.DefaultValue;
            }
            set
            {
                base.DefaultValue = value;
            }
        }
    }

XML-fldtypes:

<FieldTypes>
  <FieldType>
    <Field Name="TypeName">Vertreter_FieldType</Field>
    <Field Name="ParentType">User</Field>
    <Field Name="TypeDisplayName">Vertreter</Field>
    <Field Name="TypeShortDescription">Auswahl Vertreter</Field>
    <Field Name="UserCreatable">TRUE</Field>
    <Field Name="FieldTypeClass">CustomFieldTypes.Vertreter_FieldType, $SharePoint.Project.AssemblyFullName$</Field>
  </FieldType>
</FieldTypes>

My Contenttype the List bases on:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
...
<Field ID="{2C338272-3BC8-45bc-B33E-5FBD1223F398}"
         DisplayName="Administrator" Name="Administrator" 
         Type="Admin_FieldType" Required="TRUE"
         UnlimitedLengthInDocumentLibrary="FALSE"
     />
  <Field ID="{585CE72A-72D7-4ecc-8324-484BA1E483F1}"
         DisplayName="Vertreter" Name="Vertreter"
         Type="Vertreter_FieldType" Required="TRUE"
         UnlimitedLengthInDocumentLibrary="FALSE"
         >
  </Field>
...
  <FieldRefs>

...
     <FieldRef ID="{2C338272-3BC8-45bc-B33E-5FBD1223F398}" Name="Administrator" Required="TRUE" ShowInNewForm="TRUE" ShowInEditForm="TRUE" />
     <FieldRef ID="{585CE72A-72D7-4ecc-8324-484BA1E483F1}" Name="Vertreter" Required="TRUE" ShowInNewForm="TRUE" ShowInEditForm="TRUE" />
 ...

    </FieldRefs>
  </ContentType>
</Elements>

My environment: sharepoint 2010, visualstudio 2010

Thanks for your help!

Upvotes: 2

Views: 1164

Answers (1)

HW90
HW90

Reputation: 1983

Found the solution: I had to add List="UserInfo" to the FieldDefinition.

<Field ID="{585CE72A-72D7-4ecc-8324-484BA1E483F1}" DisplayName="Vertreter" Name="Vertreter" Type="Vertreter_FieldType" Required="TRUE" UnlimitedLengthInDocumentLibrary="FALSE" List="UserInfo">

Upvotes: 1

Related Questions