The OnPreRender solution
Need to load the js scripts in OnPreRender
and as it gets called on every field on the edit form so need to stop it from calling more than one. A boolean variable can be used for that. Here is the updated code.
var scriptsLoaded = false;
function loadScripts(){
if(!scriptsLoaded){
console.log("Loading scripts....");
scriptsLoaded = true;
RegisterSod('sp.js', '/_layouts/15/sp.js');
RegisterSod('sp.init.js', '/_layouts/15/sp.init.js');
RegisterSod('reputation.js', '/_layouts/15/reputation.js');
SP.SOD.loadMultiple(
['sp.js',
'sp.init.js',
'reputation.js'
],function(){console.log("scripts loaded");}
)
}
}
customizeFieldRendering = function () {
SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
OnPreRender: loadScripts,
Templates:{
Fields:{
'Title':{
EditForm: fancyField
}
}
}
});
};
function fancyField(ctx){
var fieldInternalName = ctx.CurrentFieldSchema.Name;
}
ExecuteOrDelayUntilScriptLoaded(customizeFieldRendering, 'clienttemplates.js');