English 中文(简体)
How to override SharePoint field rendering in EditForm?
原标题:

I have a list with a choice field, which is multiple choice - meaning many checkboxes.

I d like to render it such that it will be surrounded by a frame, for example a DIV tag with a border.

alt text (The frame should be in the HTML document)

How can I edit the Control Templates / FLDTYPES.XML / Create a control / any thing, to achieve this?

Thanks!

问题回答

It sounds like you re on the right track thinking about control templates. I think you d find some success just looking on the web for creating a custom SharePoint field type. You probably want to inherit your field type from SPFieldMultiChoice, and your control s ascx file would contain your div and its styling.

For custom field types, you typically need to create:

  • A field type class
  • A control class to represent the rendered control for your field type
  • An ascx file to contain the html scaffolding for your rendered control

This article seems a good starting point: http://www.c-sharpcorner.com/Blogs/BlogDetail.aspx?BlogId=1207

The SharePoint SDK entries on custom field types are also good enough to use as a starting point.

As stated by Ryan, using jQuery to do surround the control with a div is the cleanest way to go. It just requires a ContentEditorWebPart (CEWP) to be added to the site and the jQuery library uploaded to say a doc lib or, by using SharePoint Designer, any folder) include a reference to the jQuery library by adding a script like so to the page through the CEWP:

<script type="text/javascript" src="pathtojquerylibrary/jquery.js"> <script>

Then you would need to write some javascript code, also in the CEWP to select the control you want, add a div to the piece of html s parent you selected using jquery, then cut / paste the selected html into the new div.

it would look something like this (this code is not complete and certainly not tested):

$( query ).parent().append( <div></div> ).append($( query ).html()); 
// where  query  is the jquery selector for the control you want

You might also consider the SharePoint duct tape approach - javascript/jQuery in a content editor web part (CEWP)

This post shows you the overall method of how to get it onto a new/edit form :-

There are lots of articles about SharePoint and jQuery that would give you ideas about how you could take this further to add a border around the checkboxes, a few links :-

Disclaimer - This approach is often touted as no-code when the reality is that its more about letting you quickly the job done (often because it bypasses Administrators, change control etc) and should probably been seen for the hack it is. Powerful but use appropriately! Maybe one thing to consider is that if this stops working (service pack, upgrade to 2010, tempalte changes etc) then what is the downside - I would doubt a missing border is that critical?

See jQuery - the SharePoint bad aid for a discussion.





相关问题
SharePoint - Approaching Website Storage Limit Email

How can i go about changing the distribution list as well as the email text for the email that goes out to site collection admin when a site collection approaches it s size limit? Thanks for your ...

UI automated testing within SharePoint

I m looking for automated Functional Testing tools that can manipulate SharePoint sites, libraries, and documents thought the web interface. It needs to be extensible enough to handle any custom ...

Enable authorization on sitemap provider

I want to enable Authorization on the Site map provider. We have enabled anonymous access to the site and we want the Site map provider to be visible only to authorized users. I tried ...

SharePoint : web service permission error

I have a sharepoint site, and I am calling a standard sharepoint web service. I create the web service request like this : wsDws.Url = this.SiteAddress + @"/_vti_bin/Dws.asmx"; When I use ...

Sharepoint 2007 Data view Webpart custom parameters

I m sort of new to the custom parameters that can be setup on a DataView Webpart. There are 6 options: - None - Control - Cookie - Form - QueryString - Server Variable I think that None, Cookie and ...

热门标签