I am trying to create a custom field type in SharePoint.
My custom field type has a custom property called CustomProperty.
<FieldTypes>
<FieldType>
<Field Name="TypeName">CustomField</Field>
<Field Name="InternalType">CustomField</Field>
..............................
..............................
<PropertySchema>
<Fields>
<Field Name="CustomProperty" DisplayName="CustomProperty" Type="Text" Hidden="TRUE" />
</Fields>
<RenderPattern Name="DisplayPattern">
<Property Select="CustomProperty" />
</RenderPattern>
</FieldType>
</FieldTypes>
I am trying to render the value of this custom property in the DisplayPattern.
But it looks like the CAML is not able to reference the custom properties.
I am not getting any value for the CustomValue property even though it is set correctly.
Any idea how to refer custom properties in CAML?
Unfortunately there is no straightforward way of achieving this, from what I've seen.
Your best option is to look at using this.GetCustomProperty("CustomProperty") within the overrided GetFieldValue function (or GetFieldValueAsHtml for a Note field).
The value string passed into the GetFieldValue function is the output from your CAML, so you can append to it and pass it on out.
Here is a sample:
http://blogs.msdn.com/toddca/archive/2009/01/23/customizing-the-rendering-of-a-custom-spfield.aspx
I haven’t tried it myself, and I have no idea if changing the SchemaXml could cause any unexpected problems.
Related
I've the following usecase:
I want to use a field for autosuggest and for fulltext-search with "q"-parameter
Now the problem is: When I want to do full-textsearch and choose "_textS" or "_textM" as type, then fulltextsearch works perfectly word-based.
But because of the tokenization which takes place for "*_textM" in solr, I get only 1 lowercase-piece of the whole word when doing autosuggest with "Eid/Suggest".
For example if I have indexed "This is a value" as "_textS" I only get "this" for autosuggest. What I need as autosuggest-value is "This is a value".
What's the best way to tackle this?
If you want to use same field for autosuggest as well as search. Then you can create a copy field of that field with different fieldType. For example content is the field which is you want to use for autosuggest-search.
Then you can use content as full text-search and create an another field content_suggest for suggestions which is copy field of content with different fieldType.
<field name="content" type="_textS" indexed="true" stored="true"/>
<field name="content_suggest" type="string" indexed="true" stored="true"/>
<copyField source="content" dest="content_suggest"/>
Ok. Why would you use "copyField" instead of "DocValues" for this usecase?
I have a sharepoint list that contains a multiple lookup field. I would like to change the way its values are displayed (normaly you get links to chosen items like item1;item2;item3), so that I could for instance construct my own link to redirect me to the source list filtered by items chosen on this lookup.
I try to do that by creating a custom field by that is inheriting SPFieldLookup, but i'm a bit stuck since I can't don't know which method/property to override to change what is being displayed (if this is possible at all). Any help would be appreciated
I'd create a custom field type that inherits from SPFieldLookup. But instead of do the rendering server side I'd use a XSTL to render the field:
How to: Customize the Rendering of a Field on a List View
This way you do not have to implement a custom SPField class at all. You just have to create a custom field type definition that points to the OOTB SPLookupField.
<?xml version="1.0" encoding="utf-8" ?>
<FieldTypes>
<FieldType>
<Field Name="TypeName">CustomLookupField</Field>
<Field Name="TypeDisplayName">Custom Lookup Field</Field>
<Field Name="TypeShortDescription">Custom Lookup Field</Field>
<Field Name="FieldTypeClass">Microsoft.SharePoint.SPFieldLookup</Field>
<Field Name="ParentType">Lookup</Field>
</FieldType>
</FieldTypes>
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?
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.
I'm trying to create a solution package for a set of features within a SharePoint site. I want to create an instance of a generic list (using ListInstance in the element manifest) and add an additional column to it (since by default they only have a Title column) without having to go through activation code.
Is there a way to do this through CAML? So, far I'm sort of stuck with the idea of having to create a custom content type but that means I would have to have a separate feature that activates at the Site level to deploy the content type first.
I believe this is what you are looking for, snippets:<!--Add a field reference for the custom field.-->
<FieldRef
ID="{AD22016D-BC8B-4631-A0A3-5E84C6CFA7EC}"
Name="FavoriteColor"
Required="TRUE"
ShowInNewForm="TRUE"
ShowInEditForm="TRUE"/>
and then:
<Fields>
<Field
Type="Choice"
Name="FavoriteColor"
DisplayName="Favorite Color">
<CHOICES>
<CHOICE>Red</CHOICE>
<CHOICE>Green</CHOICE>
<CHOICE>Blue</CHOICE>
</CHOICES>
</Field>
</Fields>
Making sure it is added to the view<ViewFields>
<FieldRef Name="FavoriteColor"/>
</ViewFields>
I'd like to use the field type RichHTML in a custom content type that I'm making. However, I think that the RichHTML type comes with MOSS Publishing so I'm unsure how to add it to my content type. Right now I've tried with this:
<Field ID="{7F55A8F0-4555-46BC-B24C-222240B862AF}" Type="RichHTML" Name="NewsBodyField" DisplayName="News Body" StaticName="NewsBodyField" Hidden="False" Required="True" Sealed="False" />
<Field ID="{7F55A8F0-4555-46BC-B24C-222240B862AF}" Type="RichHtmlField" Name="NewsBodyField" DisplayName="News Body" StaticName="NewsBodyField" Hidden="False" Required="True" Sealed="False" />
I know that when I want to access this custom field using a CQWP, I can export it and add it to my CommonViews using 'RichHTML', however that doesn't work here.
Any help regarding how to add a Rich Html Field to a custom content type would be much appreciated.
I figured it out myself. The type you're looking for is "HTML" not RichHTML.