Pages

Thursday, September 11, 2014

Client Side Rendering using JSLink – Post 02 – Customize List Forms

Introduction

In my last post I described how to startup with Client Side Rendering using JSLink with basic example. In this post I will describe “What are the places you can deploy JavaScript files in order to use in SharePoint development” and “How can we use rendering; in order to customize list forms”.

What are the places you can deploy JavaScript files in order to use in SharePoint development?

In my last post I had used layouts folder which is inside the 15 hive. But there are more options where we can deploy JavaScript files in order to use them in JSLink property. So these option can be useful for the developers who want to develop SharePoint hosted apps and who don’t have the access to local file system. JSLink property accepts below SharePoint tokens.

~site – The URL of the current website. (Recommended to use in SharePoint hosted apps development)

~sitecollection – The URL of the parent site collection of the current website.

~layouts – The URL of the Layouts virtual folder for the current website. You don’t have to worry about 14 hive or 15 hive.

~sitecollectionlayouts – The URL of Layouts folder in the current site collection (/sites/spsite/_layouts/15)

~sitelayouts – The URL of Layouts folder in the current site (/spsite/spweb/_layouts/15)

If you want to use multiple JavaScript file on a single JSLink property you can use “|” symbol.

Eg. ~layouts/folder001/test.js | ~layouts/folder002/test.js

How can we use rendering in order to customize list forms?

In the first post I described how to customize the default view form. In this post I will describe how to customize New form, Edit form and the Display form by changing the scope in JavaScript. I will show how to customize the New form and you can use the same for other forms as well.

Solution

(function () {

// Initialize the variables for overrides objects

var overrideCtx = {};

overrideCtx.Templates = {};

overrideCtx.BaseViewID = "NewForm";

overrideCtx.ListTemplateType = "10000";

/*

* Using the Fields override leaves the rest of the rendering intact, but

* allows control over one or more specific fields in the existing view