Cloud

The LookupWithPicker is not just for Lookup Fields

I recently had a client requirement to associate documents and pages within SharePoint to specific pages.The client wanted to associate the documents / pages through metadata. After thinking about this for a while I remembered the lookup with picker control on CodePlex. The picker control on CodePlex was designed to work with lookup fields and I wasn’t prepared to have a metadata field for each pages library or document library in the system.I decided to change the lookup with picker to perform a site query be content type and show the results title and file reference. To do this I had one obstacle to overcome…what kind of field should this be? The easiest way was to make it a note field and require the users edit the field on the page. In this post I will explain what I had to change in the picker to get this to work.

LookupWithPickerField

A custom field control was required for displaying the field control on the page layout. The field control resembles a picker field. While in edit mode the users would see the following:

 

The field displays the selected item along with the icon to open the picker. I removed the icon to validate typed in items and also disabled the ability to type in the item. The custom field also contains the following properties:

·ContentTypeName – This property is used by the picker dialog for the site query

·IsDocLib – Since the site query needs the type of library to search I need to know if it is a pages library or document library

·AllowMultipleValues – Allows for multi select in the picker dialog

CustomLookupEntityEditor

This class is the control that is rendered in the picture above. The class extends the EntityEditorWithPicker class. The code for this class overrides the init method and sets the PickerDialogType, AllowTypeIn, and the CheckButtonImageName. AllowTypeIn is set to false since I do not want users to manually type in the field and the CheckButtonImageName is set to blank.gif because I do not want to show the button.

CustomLookupPickerDialog

The next class I changed was the CustomLookupPickerDialog. I added the fields I wanted to display in the dialog along with the column widths for each field. n this case I am displaying Title and FileRef.

CustomLookupQueryControl

The CustomLookupQueryControl is the class that is doing all of the heavy lifting. This class takes the content type name supplied on the LookupWithPickerField properties and uses it to query the entire site. When a user clicks the book icon that is displayed in the field control the results will appear like the following image:

A user can then select the item(s) they are looking for.If there is a lot of data the search results can be narrowed by typing text in the box at the top and clicking the search button. The two fields that are displayed in the picker are the fields that are saved in the note field as part of the metadata.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe to the Weekly Blog Digest:

Sign Up
Follow Us
TwitterLinkedinFacebookYoutubeInstagram