SharePoint Pals
 | Sign In
How to add CSR based JS file in JS link in Edit form Webpart in SharePoint office 365
by Arunraj Venugopal 24 Aug 2016
Author
SharePoint Developer
Visits   
Today  :   18     Total  :    2266

Let us look at the functionality of CSR client side rendering which is one of the new concepts in SharePoint 2013 online. To change the behavior of view & its appearance, new form, Edit Form and Display Form at runtime, jquery used in the SharePoint 2007 and its later version.

In SharePoint 2013 office 365, we have a concept called Client side rendering and its easy way of debugging code will help to achieve tasks such as changing the behavior of view and form (New, Edit & Display) rendering and Search Result etc.,.

To edit the page, ToolPaneView=2 would be used at the end the url.

In SharePoint online, ToolPaneView=2 won’t work in usual way.

In order to edit the Edit form page, go to Advance setting in the list setting and select the option 1

1. Classic Experience(Select)

2. New experience

3. Default Experience.

Edit form page get loaded with edit mode once Sharepointurl/editform.aspx?ID=2&ToolPaneView=2 is entered in the browser

Prepare a CSR based js file and placed in the asset library. Go to web part properties of Edit form and paste the path of the js file in the JSlink text box

(

function () {

var overrideCtx = {};

overrideCtx.Templates ={};

overrideCtx.Templates.Fields = {

'Change_x0020_Comments' : { 'EditForm' : Testing } For Reader: “Change_x0020_Comments” is a internal name. Testing is the function name.

};

SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);

}) ();

function Testing(ctx) {

var fieldval = ctx.CurrentItem[ctx.CurrentFieldSchema.Name]; For Reader: It has the reference of comment field, which will be manipulated as per logic

var TestTitle = fieldval.toString().replace(" ", "");

TestTitle='<textarea rows="25" cols="20" id="Change_x0020_Comments_ab250304-f850-4895-86d3-0a2721427864_$TextField" title="Change Comments" class="ms-long"></textarea>';

return TestTitle;

}

The code in the box takes reference of the comments field “Change Comments” and replaces the existing value as blank while loading Edit form of sharepoint list

TestTitle='<textarea rows="25" cols="20" id="Change_x0020_Comments_ab250304-f850-4895-86d3-0a2721427864_$TextField" title="Change Comments" class="ms-long">Here is the value for Comment field</textarea>';

This function is building up an object, which is then used to register a template override.

(

function () {

var overrideCtx = {};

overrideCtx.Templates ={};

overrideCtx.Templates.Fields = {

'Change_x0020_Comments' : { 'EditForm' : Testing } For Reader: “Change_x0020_Comments” is a internal name. Testing is the function name.

};

SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);

}) ();

The object takes the following properties:

· View

· Header

· Body

· Footer

· Group

· Item

· Fields

· OnPreRender

· OnPostRender

The CSR code must be the adhere to the following rules

· FieldName – This is the internal name of the field you want to override.

· Scope – This defines when to override the field. The choices are “View”,”DisplayForm”,”EditForm”, and “NewForm”

· Override – The actual override. This can be a HTML string with JavaScript embedded, or a function to be executed. In the former, it should be in the format: “

The code in the box takes reference of the comments field “Change Comments” during the Edit form loading and replace the value blank.

blog comments powered by Disqus

SharePoint Pals

Pals
SharePoint Pals, a community portal for SharePoint developers, Administrators and End Users. Let's join hands and share the point together.
Read this on mobile

Training

Angular Js Training In Chennai
Advanced Angular Js training with real world developer scenarios
Angular Js, Web Api and Ionic for .Net Developers
All in one client side application development for .Net developers
Angular Js For SharePoint Developers
Get ready for the future. Its no more just C#

Get Connected

SharePoint Resources

SharePoint 2013 and 2010 Web Parts
Free Web Parts with Source Code for SharePoint Community




SharePoint 2013 Books and Tutorials
Collection of free SharePoint 2013 books and tutorials (eBooks, pdfs)

Supported By

Contribute your article and be eligible for a one month Free Subscription for Plural Sight. The Author of the most popular New Article (published in the previous month) will be awarded with a Free One month Plural Sight Subscription. Article can be sent to articles@sharepointpals.com in a word document.

Related Resources

Recent Tweets

Twitter January 15, 00:25
How To Enable Target Value And Actual Value In #D3 Gauge Chart https://t.co/VxSi4QnNrC

Twitter January 15, 00:24
How To Open #SharePoint List Hyperlink Column In Modal #Popup Window https://t.co/EQ7HkoZDkX

Twitter January 15, 00:24
Quick Introduction To #Asp.NetCore And It’s Features https://t.co/zAXObHCFpH

Twitter January 15, 00:22
How To Configure #PerformancePoint Services To Use Secure Store In #SharePoint 2013 https://t.co/LEwnUoI7EY

Twitter January 15, 00:21
How To Block Or Disable #Office365 Services https://t.co/Yvp2VPFIRP

Follow us @SharePointPals
Note: For Customization and Configuration, CheckOutRecent Tweets Documentation