1

In producing a JSLink custom rendering for a particular field (I use Fields:, EditForm and NewForm templates), I seem to have gotten the field's default name rendered "for free" as its label, but I want a custom label to show in its place.

How would I go about doing this?

(I'm brand new to JSLink and CSR technology).

Josh

1

You are now rendering only the Fields value

You would either

  • Render the whole Form yourself

  • or "go in" after the page loaded and change the DOM

The last one might be easier with some creative JavaScript, because you can't easily select that label with Selectors..

in your current render output, add a dummy IMG

<IMG src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw=="
  onload="{
            var TR=this.parentNode.parentNode;
            var label=TR.firstChild.firstChild;
            label.innerHTML="MY NEW LABEL";
          }"/>

You might need to change the DOM locations for your scenario

The src is a blank image 1px image which causes NO network load, but will trigger the onload function

Once it loads it walks up the DOM to the corresponding label

  • Got it. I know what to do now. In fact, I can't render the whole form myself because the JSLink is tied - by design - to a Site Column that's used in 40+ sites, on forms that differ from each other. To me, it seems like a serious design flaw that CSR doesn't give us a way to customize all the facets of just one column without having to render the whole form. Since this design has gone unmodified for 3+ years, it doesn't seem like Microsoft is about to change it any time soon. Thanks for this. – Josh Korn Nov 9 '16 at 15:24
  • There are more design flaws in CSR (and DisplayTemplates) And the current direction Microsoft is taking with the SharePoint Framework... any CSR knowledge you acquire can be thrown in the bin anyway. You might be interested in my pet-github-project iCSR .. which I shelved because at the moment SharePoint has no CSR/JSLink (or any script) future – Danny '365CSI' Engelman Nov 9 '16 at 15:33
  • Yes, that IMG trick is one of my favourites, is also great to stuff it all in Calculated Columns.. and not have to use CSR.. viewmaster365.com/#/How – Danny '365CSI' Engelman Nov 9 '16 at 20:41

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.