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 () { 

  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
            'NewForm': setBody
            'NewForm': setProject



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);

  • I do not understand the problem... – Juan Pablo Pussacq Laborde Jun 15 '17 at 13:30
  • I want to set value of already being created filed suppose Task Name, but to set value of Task Name I do not know the code,but somehow I got the code to create the field using CSR I hope you understand that creating a whole control is not a good ida just to set it's value – codemirror Jun 15 '17 at 13:34
  • You do not like this: "return SPFieldText_Edit(ctx); "? – Juan Pablo Pussacq Laborde Jun 15 '17 at 14:00
  • 1
    @codemirror in theory you are right, creating the whole control seems like overkill if you just want to set its value. But from a practical perspective, you have a way to do what you want that works, why not just go with what's working already? As they say: if it ain't broke, don't fix it. – Dylan Cristy Jun 15 '17 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.