问题
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:
(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?
回答1:
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.
来源:https://stackoverflow.com/questions/5082936/sharepoint-2007-create-a-multi-line-text-custom-property-for-a-custom-field-typ