{"id":1654,"date":"2016-05-30T12:48:54","date_gmt":"2016-05-30T10:48:54","guid":{"rendered":"https:\/\/blog.kodono.info\/wordpress\/?p=1654"},"modified":"2017-07-11T16:12:44","modified_gmt":"2017-07-11T14:12:44","slug":"load-a-script-once-a-dispform-is-fully-shown-in-sharepoint-2013","status":"publish","type":"post","link":"https:\/\/blog.kodono.info\/wordpress\/2016\/05\/30\/load-a-script-once-a-dispform-is-fully-shown-in-sharepoint-2013\/","title":{"rendered":"Load a script once a DispForm is fully shown in Sharepoint 2013"},"content":{"rendered":"<p>Sharepoint 2013 introduced the <a href=\"http:\/\/jsuhail.blogspot.fr\/2014\/09\/client-side-rendering-using-jslink-post_30.html\">JSLink<\/a>. This is very useful to play with forms and views.<\/p>\n<p>My attempt here is to remove some rows from the DispForm. To do so I needed to trigger an action as soon as the fields rendering has been done. After different tries, I finally came up with the <code>PostRender<\/code> option.<\/p>\n<pre class=\"brush:javascript\">\r\n\/\/ https:\/\/gist.github.com\/Aymkdn\/98acfbb46fbe7c1f00cdd3c753520ea8\r\nfunction loadExt(e,t){var s=this;s.files=e,s.js=[],s.head=document.getElementsByTagName(\"head\")[0],s.after=t||function(){},s.loadStyle=function(e){var t=document.createElement(\"link\");t.rel=\"stylesheet\",t.type=\"text\/css\",t.href=e,s.head.appendChild(t)},s.loadScript=function(e){var t=document.createElement(\"script\");t.type=\"text\/javascript\",t.src=s.js[e];var a=function(){++e&lt;s.js.length?s.loadScript(e):s.after()};t.onload=function(){a()},s.head.appendChild(t)};for(var a=0;a&lt;s.files.length;a++)\/\\.js$|\\.js\\?\/.test(s.files[a])&#038;&s.js.push(s.files[a]),\/\\.css$|\\.css\\?\/.test(s.files[a])&#038;&s.loadStyle(s.files[a]);s.js.length>0?s.loadScript(0):s.after()}\r\n\r\n\/\/ verify when all scripts have been loaded\r\nvar loadExtLoaded = false;\r\nfunction checkExt(ctx) {\r\n  if (loadExtLoaded) {\r\n    \/\/ here you can call a function that is in one of the called script\r\n  } else {\r\n    setTimeout(function() { checkExt(ctx) }, 50);\r\n  }\r\n}\r\nloadExt([\r\n  'file_you_want_to_load.js',\r\n  'style_you_want_to_load.css',\r\n  'no_cache_file.js?timestamp='+(Date.now())\r\n], function() {\r\n  loadExtLoaded=true;\r\n});\r\n\r\n(function() {\r\n  function onLoad(ctx) {\r\n    checkExt(ctx);\r\n  }\r\n\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         \/\/ only trigger when everything is loaded\r\n        \/\/ --> ctx.ListData.Items[0] all the fields\r\n        if (ctx.ListSchema.Field[0].Name === \"Attachments\") {\r\n          onLoad(ctx)\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>Sharepoint 2013 introduced the JSLink. This is very useful to play with forms and views. My attempt here is to remove some rows from the DispForm. To do so I needed to trigger an action as soon as the fields rendering has been done. After different tries, I finally came up with the PostRender option. [&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":[13,33],"tags":[24,152,158,117,166],"class_list":["post-1654","post","type-post","status-publish","format-standard","hentry","category-niveau-intermediaire","category-programmation","tag-javascript","tag-niveau-intermediaire","tag-programmation","tag-sharepoint","tag-sharepoint-2013"],"_links":{"self":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/1654","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=1654"}],"version-history":[{"count":5,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/1654\/revisions"}],"predecessor-version":[{"id":1824,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/1654\/revisions\/1824"}],"wp:attachment":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/media?parent=1654"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/categories?post=1654"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/tags?post=1654"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}