{"id":1698,"date":"2016-11-03T16:02:07","date_gmt":"2016-11-03T15:02:07","guid":{"rendered":"https:\/\/blog.kodono.info\/wordpress\/?p=1698"},"modified":"2016-11-03T16:02:07","modified_gmt":"2016-11-03T15:02:07","slug":"hide-a-field-into-a-form-with-jslink-based-on-fields-description-sharepoint","status":"publish","type":"post","link":"https:\/\/blog.kodono.info\/wordpress\/2016\/11\/03\/hide-a-field-into-a-form-with-jslink-based-on-fields-description-sharepoint\/","title":{"rendered":"Hide a field into a form with JSLink based on field&#8217;s description [Sharepoint]"},"content":{"rendered":"<p>On Sharepoint 2013 I was trying to hide a field (the complete row) based on some elements into its description.<\/p>\n<p>To do so we will call our file using the JSLink (see <a href=\"https:\/\/blog.kodono.info\/wordpress\/2016\/08\/25\/bypass-a-lookup-field-not-displayed-because-of-threshold-on-newform-and-editform-sharepoint-2013\/\">my previous post<\/a> about it).<br \/>\nThe JS file looks like that:<\/p>\n<pre class=\"brush:javascript\">\r\n(function() {\r\n  \/\/ do some actions as soon as the fields are shown\r\n  var loadAfterForm = {\r\n    Templates: {\r\n      OnPostRender:function(ctx) {\r\n        \/\/ hide the field\/row when \"[INTERNAL USE - DO NOT CHANGE]\" is detected in the field's description\r\n        if (ctx.ListSchema.Field[0].Description.indexOf('[INTERNAL USE - DO NOT CHANGE]') > -1) {\r\n          \/\/ get the element that represents the field\r\n          var elem = document.querySelector('[id^=\"'+ctx.ListSchema.Field[0].Name +'_'+ ctx.ListSchema.Field[0].Id+'\"]');\r\n          while (elem) {\r\n            elem = elem.parentNode;\r\n            if (elem) {\r\n              if (elem.tagName===\"BODY\") break;\r\n              if (elem.tagName === \"TD\" &#038;& elem.className.indexOf(\"ms-formbody\") > -1) {\r\n                \/\/ hide the whole row\r\n                elem.parentNode.style.display=\"none\";\r\n                break;\r\n              }\r\n            }\r\n          }\r\n        }\r\n      }\r\n    }\r\n  }\r\n  SPClientTemplates.TemplateManager.RegisterTemplateOverrides(loadAfterForm);\r\n})();\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>On Sharepoint 2013 I was trying to hide a field (the complete row) based on some elements into its description. To do so we will call our file using the JSLink (see my previous post about it). The JS file looks like that: (function() { \/\/ do some actions as soon as the fields are [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","hide_page_title":"","footnotes":""},"categories":[170,11,33],"tags":[123,24,151,158,117],"class_list":["post-1698","post","type-post","status-publish","format-standard","hentry","category-english","category-niveau-debutant","category-programmation","tag-english","tag-javascript","tag-niveau-debutant","tag-programmation","tag-sharepoint"],"_links":{"self":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/1698","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/comments?post=1698"}],"version-history":[{"count":2,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/1698\/revisions"}],"predecessor-version":[{"id":1700,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/1698\/revisions\/1700"}],"wp:attachment":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/media?parent=1698"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/categories?post=1698"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/tags?post=1698"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}