简体   繁体   中英

Sharepoint 2007: Create a multi-line text custom property for a custom field type?

I'm trying to extend the built-in Choice field type to include another piece of data: a correct answer. With this, users would be able to create their own tests directly within Sharepoint instead of having to use InfoPath or some other convoluted solution. I was hoping to just inherit the existing SPFieldChoice type and add one more custom property to hold an integer representing the correct answer from the choices entered.

I've got a FieldTestQuestion class that inherits from SPFieldChoice along with a pretty basic TestQuestionFieldControl class inheriting from RadioButtonChoiceField. My fldtypes_TestQuestionField.xml file:

  <FieldTypes>
    <FieldType>
        <Field Name="TypeName">TestQuestion</Field>
        <Field Name="ParentType">Choice</Field>
        <Field Name="TypeDisplayName">Test Question (Multiple choice)</Field>
        <Field Name="TypeShortDescription">Test Question (Multiple choice)</Field>
        <Field Name="UserCreatable">TRUE</Field>
        <Field Name="ShowInColumnTemplateCreate">TRUE</Field>
        <Field Name="FieldTypeClass">MyCustomFieldTypes.FieldTestQuestion,MyCustomFieldTypes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=****</Field>
        <PropertySchema>
            <Fields>
                <Field Name="CorrectAnswer" DisplayName="Correct answer (line number)" Type="Integer">
                    <Default></Default>
                </Field>
            </Fields>
        </PropertySchema>
    </FieldType>
  </FieldTypes>

Unfortunately, this is what renders when I try adding a column of this type: 我的自定义属性
(source: mudman.us )

No option to add the choices as with the Choice field type: 内置Choice字段类型上的自定义多行文本属性
(source: mudman.us )

What do I need to put in my fldTypes_.xml to tell Sharepoint to either (a) use the existing custom properties for the Choice column and ADD the extra property I specified or (b) specifically define a multi-line text custom property?

It would appear the Choice input box is being created specifically for SPFieldChoice columns; one of many un-inheritable features. This means that you're unlikely to be able to persuade SharePoint to reproduce it for your custom field type.

My advice would be to go for option b), and create it yourself. I believe adding this to the <fields> element will do the trick:

<Field Name="ChoiceFix" DisplayName="Type each choice on a separate line:" Type="Note" />

Be warned that I haven't tested this solution reliability, and you may have to go down the spiky and unpleasant route of making your own Field Editor Control.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM