none
SharePoint 2013 - Using JSLinks to Hide a Column in an Edit Form RRS feed

  • Question

  • Hello Community!

    I am using JSLinks in a SharePoint 2013 List Edit Form.  My code is designed to hide a field in the form, the field is called "MTID".  The code file is store in the Site Assets Library and the file is called "HideFields.js", with the JSLinks URL being "~site/SiteAssets/JQuery/HideFields.js".  The code is listed below.  Can anyone tell me why the code is not hiding the field as intended?

    Thanks!

    Tom

    //Hide Fields
    //JSLinks Inline Style Applied to Edit Form to Hide MTID Field
    //~site/SiteAssets/JQuery/HideFields.js
    
    (function () {
    	var editFormFieldCtx = {};
    	editFormFieldCtx.Templates = {};
    	editFormFieldCtx.Templates.Fields = {
    	"MTID": {
    	"EditForm": HideEditFormTemplate
    	}};
    	SPClientTemplates.TemplateManager.RegisterTemplateOverrides(editFormFieldCtx);
    })();
    
    function HideEditFormTemplate(ctx) {
    	var _editFormField = SPClientTemplates.Utility.GetFormContextForCurrentField(ctx);
    	var _editFormFieldId = _editFormField.fieldSchema.Id;
    	var _editFormtFieldName = _editFormField.fieldName;
    	var _editFormFieldDiv = _editFormFieldName + '_' + _editFormFieldId;
    	var result += '<div><input id=' + _editFormFieldId + ' type="text" name=' + _editFormtFieldName + ' hidden='true' /></div>';
    	return result;
    }


    Tom Molskow - Senior SharePoint Architect - Microsoft Community Contributor 2011 and 2012 Award - Linked-In - SharePoint Gypsy

    Friday, March 3, 2017 12:31 AM

Answers

  • Hi,

    The js contains a syntax error, I did update based on my test.

     

    //Hide Fields
    //JSLinks Inline Style Applied to Edit Form to Hide MTID Field
    //~site/SiteAssets/JQuery/HideFields.js
    
    (function () {
    	var editFormFieldCtx = {};
    	editFormFieldCtx.Templates = {};
    	editFormFieldCtx.Templates.Fields = {
    	"MTID": {
    	"EditForm": HideEditFormTemplate
    	}};
    	SPClientTemplates.TemplateManager.RegisterTemplateOverrides(editFormFieldCtx);
    })();
    
    function HideEditFormTemplate(ctx) {
    	var _editFormField = SPClientTemplates.Utility.GetFormContextForCurrentField(ctx);
    	var _editFormFieldId = _editFormField.fieldSchema.Id;
    	var _editFormtFieldName = _editFormField.fieldName;
    	var _editFormFieldDiv = _editFormFieldName + '_' + _editFormFieldId;
    	//var result += '<div><input id=' + _editFormFieldId + ' type="text" name=' + _editFormtFieldName + ' hidden='true' /></div>';
    	var result;
        result+='<div><input id='+ _editFormFieldId + ' type="hidden" name=' + _editFormtFieldName + ' /></div>';
    	return result;
    }

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    • Marked as answer by Tom Molskow Monday, March 6, 2017 7:13 PM
    Monday, March 6, 2017 1:38 AM

All replies

  • Hi,

    Try to update your control as below.

    <input id=' + _editFormFieldId + ' type="hidden" name=' + _editFormtFieldName + ' />

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Friday, March 3, 2017 3:33 AM
  • Hey Lee,

    I did make the changes you suggested but the field is still not being hidden.  Here is the code with your adjustment added:

    //Hide Fields
    //JSLinks Inline Style Applied to Edit Form to Hide MTID Field
    //~site/SiteAssets/JQuery/HideFields.js
    
    (function () {
    	var editFormFieldCtx = {};
    	editFormFieldCtx.Templates = {};
    	editFormFieldCtx.Templates.Fields = {
    	"MTID": {
    	"EditForm": HideEditFormTemplate
    	}};
    	SPClientTemplates.TemplateManager.RegisterTemplateOverrides(editFormFieldCtx);
    })();
    
    function HideEditFormTemplate(ctx) {
    	var _editFormField = SPClientTemplates.Utility.GetFormContextForCurrentField(ctx);
    	var _editFormFieldId = _editFormField.fieldSchema.Id;
    	var _editFormtFieldName = _editFormField.fieldName;
    	var _editFormFieldDiv = _editFormFieldName + '_' + _editFormFieldId;
    	//var result += '<div><input id=' + _editFormFieldId + ' type="text" name=' + _editFormtFieldName + ' hidden='true' /></div>';
    	var result += '<div><input id=' + _editFormFieldId + ' type="hidden" name=' + _editFormtFieldName + ' /></div>';
    	return result;
    }

    Thanks!

    Tom


    Tom Molskow - Senior SharePoint Architect - Microsoft Community Contributor 2011 and 2012 Award - Linked-In - SharePoint Gypsy

    Friday, March 3, 2017 6:27 PM
  • Hi,

    The js contains a syntax error, I did update based on my test.

     

    //Hide Fields
    //JSLinks Inline Style Applied to Edit Form to Hide MTID Field
    //~site/SiteAssets/JQuery/HideFields.js
    
    (function () {
    	var editFormFieldCtx = {};
    	editFormFieldCtx.Templates = {};
    	editFormFieldCtx.Templates.Fields = {
    	"MTID": {
    	"EditForm": HideEditFormTemplate
    	}};
    	SPClientTemplates.TemplateManager.RegisterTemplateOverrides(editFormFieldCtx);
    })();
    
    function HideEditFormTemplate(ctx) {
    	var _editFormField = SPClientTemplates.Utility.GetFormContextForCurrentField(ctx);
    	var _editFormFieldId = _editFormField.fieldSchema.Id;
    	var _editFormtFieldName = _editFormField.fieldName;
    	var _editFormFieldDiv = _editFormFieldName + '_' + _editFormFieldId;
    	//var result += '<div><input id=' + _editFormFieldId + ' type="text" name=' + _editFormtFieldName + ' hidden='true' /></div>';
    	var result;
        result+='<div><input id='+ _editFormFieldId + ' type="hidden" name=' + _editFormtFieldName + ' /></div>';
    	return result;
    }

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    • Marked as answer by Tom Molskow Monday, March 6, 2017 7:13 PM
    Monday, March 6, 2017 1:38 AM