I want to set field values of different fields after OnPostRender using JS Link.
I am able to create the field and set value, but I want to set value only and for the little task I think creating the whole field is not a good idea.
Below is the required missing code
(function () {
SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
OnPreRender: function() { console.log('CSR OnPreRender'); },
OnPostRender: [
// set value in Title field
// How to do this ?
]
});
})();
Below is the Working code which creates field and also sets value
(function () {
var ctx = {};
ctx.Templates = {};
ctx.Templates.Fields = {
'Title': {
'NewForm': setTitle
},
'Body':{
'NewForm': setBody
},
'Project':{
'NewForm': setProject
}
};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(ctx);
})();
function setTitle(ctx) {
var temp = 'Title 1'; //extract parameter from a query string
ctx.CurrentFieldValue = temp ; //set field value
return SPFieldText_Edit(ctx);
}
function setBody(ctx) {
var temp = 'body text lorel ipsum';
ctx.CurrentFieldValue = temp ;
return SPFieldText_Edit(ctx);
}
function setProject(ctx) {
var temp = 'p2';
ctx.CurrentFieldValue = temp ; //set lookup field value
return SPFieldChoice_Edit(ctx);
}