1

JSLink don't work for me in this case, can some body say is this Code below ok.

    (function () {
    (window.jQuery || document.write('<script src="https://teamsite/_catalogs/masterpage/jquery-1.10.2.min.js"><\/script>'));
    (window.jQuery || document.write('<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"><\/script>'));
    var hiddenFiledContext = {};
    hiddenFiledContext.Templates = {}; 
    hiddenFiledContext.Templates.OnPostRender = hiddenFiledOnPreRender;
    hiddenFiledContext.Templates.Fields = {
        "Field1": {
            "NewForm": hiddenFiledTemplate,
            "EditForm": hiddenFiledTemplate
        }
    };  SPClientTemplates.TemplateManager.RegisterTemplateOverrides(hiddenFiledContext);
})();
function hiddenFiledTemplate() {
    return "<span class='csrHiddenField'></span>";
}
function hiddenFiledOnPreRender(ctx) {
    jQuery(".csrHiddenField").closest("tr").hide();
}
  • What exactly is not working? What's the expected and actual result? Any errors thrown? – Daniel Stölzner Jun 28 '16 at 12:58
  • No errors, it must hide Field1 in NewForm and EditForm on a List View. But nothing is happen after using JSLink. – sandimraka Jun 28 '16 at 13:08
  • It will be much quicker (if you're comfortable) to debug this using the IE developer toolbar. Setup breakpoints and see where it is failing. – Ransher Singh Jun 28 '16 at 13:24
  • 1
    First of all you are loading jQuery twice – Danny '365CSI' Engelman Jun 28 '16 at 13:27
  • Yea loading twice, if the local don't work the other will, never used IE developer toolbar before. – sandimraka Jun 28 '16 at 13:29
4

Always great to see the hideFiledTemplate typo..

You do not need a 90 KB library and all the loading hassles to hide a Filed .. ehm Field

(function(){
  var hideField="<span class='csrHiddenField'></span>";

  var overrides = {};
  overrides.Templates = {}; 
  overrides.Templates.Fields = {
    "DueDate": {
      "NewForm": hideField,
      "EditForm": hideField
    }
  };  
  overrides.Templates.OnPostRender = function () {
    document.querySelectorAll(".csrHiddenField").forEach(function(field){
      GetAncestor( field , 'TR' ).style.display='none';
    });
  };

  SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrides);
})();

Notes:

  • Overrides are Strings, so no need to define a function and return a String
  • No need to declare a separate function (OnPostRender) if you only call it once
  • This is not MDS save, use the Cisar CSR editor to get the MDS save boilerplate
  • GetAncestor is defined by SharePoint core code

And Dylan Christy has an even better way:

CSR Hide a field on form but not with jQUery

which you would have found had you searched 'csr hide field' before asking!!!

  • With jQuery or not it's not working in this case, my bad with the csr hide field, sorry, but i'm missing something and i can't find the problem, it's not working. – sandimraka Jun 30 '16 at 7:27
  • Use the Cisar Chrome extension, paste this code, and use the correct Internal fieldname (note: the currect Cisar 1.3 version has a bug, Andrei is working on a fix as we speak) In the mean time set the JSLink on the Form webpart by hand.. when you then ope Cisar it will work – Danny '365CSI' Engelman Jun 30 '16 at 9:41
  • The console shows no error, but Chrome shows Error occured when saving file. Thank you very much for helping me. – sandimraka Jun 30 '16 at 12:23

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.