2

I want to apply the JSLink file to the field to render it differently.

<Field ID="{2F30125C-D2C9-459F-9AC5-1796F52C0C4B}"
     Name="oiplbDepartment"
     StaticName="oiplbDepartment"
     Type="TaxonomyFieldType"
     ShowField="Term1033"
     EnforceUniqueValues="FALSE"
     DisplayName="$Resources:OIPLBIntranet,fldoiplbDepartmentDisplayName;"
     Description="$Resources:OIPLBIntranet,fldoiplbDepartmentDescription;"
     Group="$Resources:OIPLBIntranet,grpFields;"
     DisplaceOnUpgrade="TRUE"
     JSLink="~siteCollection/Style%20Library/LofbergsIntranet/Scripts/SingleDepartment.js">

My jslink file code:

(function () {
    var favoriteColorContext = {};

    // You can provide templates for:
    // View, DisplayForm, EditForm and NewForm
    favoriteColorContext.Templates = {};
    favoriteColorContext.Templates.Fields = {
        "oiplbDepartment": {
            "View": favoriteColorViewTemplate
        }
    };

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(
        favoriteColorContext
        );
})();

// The favoriteColorViewTemplate provides the rendering logic
// the custom field type when it is displayed in the view form.
function favoriteColorViewTemplate(ctx) {
    var color = ctx.CurrentItem[ctx.CurrentFieldSchema.Name];
    return "<h1>Hello</h1>";
}

I am not getting the field rendered differently. What am I missing?

1 Answer 1

2

Overriding JSLink property via field xml definition or c# code is a nice way to link your JavaScript file to the particular field. However, not all the fields could be overwritten this way.

For example, Taxonomy field has the following JSLink definition:

// Microsoft.SharePoint.Taxonomy.TaxonomyField public override string

 JSLink {
     get
     {
         return "SP.UI.Taxonomy.js|SP.UI.Rte.js(d)|SP.Taxonomy.js(d)|ScriptForWebTaggingUI.js(d)";
     } }

This means you cannot modify the look and feel for your Taxonomy field. Also, you can’t do that for Taxonomy, Related Items or Task Outcome field. All of these fields return particular JSLink which can’t be changed

Please see below for reference

http://spdevlab.com/2013/07/07/5-facts-about-jslink-in-sharepoint-2013-you-might-not-know/

1
  • Nadeem, I think I'm missing something here. Why does the definition (or syntax) preclude modifying the look and feel of a TaxonomyField?
    – Josh Korn
    Nov 18, 2014 at 23:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.