Using jquery in the Caml of custom field types

Source: Internet
Author: User
Tags html tags

This article will implement the CAML invocation of JQuery AJAX for the custom fields in SharePoint 2007 in two ways. respectively:

1, the traditional way of writing code, with Fldtypes_ your field type. XML, build custom field types.

2, using Jianyi spcamleditor tool, directly modify the CAML of a list of fields.

The former is highly reusable, and the latter is simple and fast, and you can choose according to your own situation.

We know that you can write client-side code, such as HTML tags, CSS, and JavaScript code, in the schema caml of a field. Thanks to the power of jquery Ajax, we can further process the server-side query asynchronously in field CAML without reloading the page. The combination of the two will certainly enrich the experience of custom fields.

First, let's look at the implementation steps of the traditional coding method:

Create a new project, in this case, we use the class Library project directly. Give it a name:

Copy the Hive directory (which is the structure of C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12, which is what Todd Bleeker says), To place the custom field type. Rename Class1.cs (here for QuickViewField.cs) as needed

We created the XML folder to hold the field definition file Fldtypes_ ..., which will call jquery in this file. We also created Layouts\jquery to store the jquery files. You can download it from the http://jquery.com/.

There are many ways to reference jquery files. You can refer directly to Google, but this approach is not recommended for production environments. You can also store it somewhere under the _layouts, or put it in the Style gallery, and look at the person's liking completely.

In this case, I decided to put it under layouts.

Next, you need to add a strong name to your component.

Now, start writing code for QuickViewFieldType.cs:

public class QuickViewFieldType:SPFieldText
{
     public QuickViewFieldType(Microsoft.SharePoint.SPFieldCollection fields, string typeName, string  displayName)
         : base(fields, typeName, displayName)
     { }
     public QuickViewFieldType(SPFieldCollection fields, string fieldName)
         : base(fields, fieldName)
     { }
     public override void OnAdded(SPAddFieldOptions op)
     {
         base.OnAdded(op);
         this.ShowInDisplayForm = false;
         this.ShowInEditForm = false;
         this.ShowInNewForm = false;
         this.Update(true);
     }
}

There are 2 default constructors inside. The onadded override method is to ensure that the field is not displayed in disp/edit/newform.aspx (that is, the list is displayed, edited, new page).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.