1

I created a custom layout for my SharePoint new record form, I added to content editors where I placed the html and .js file.

For some reason when I enter in the .js file the text box fields appear in the preview menu. but when I go to enter in a new record the input fields are not there... anyone know why?

Script I am using. enter image description here

enter image description here

enter image description here Now when I actually go into enter are record, those boxes disappear... why is that happening

enter image description here

  • Matt..Please copy the code instead of using screen shots. – jpollar Feb 10 '15 at 20:50
  • This is the script <script src="//code.jquery.com/jquery-1.10.1.min.js"></script> <style type="text/css"> .ms-formtable {display:none;} </style><script type="text/javascript"> $(document).ready(function() { $("span.hillbillyForm").each(function() { displayName = $(this).attr("data-displayName"); elem = $(this); $("table.ms-formtable td").each(function(){ if (this.innerHTML.indexOf('FieldName="'+displayName+'"') != -1){ $(this).contents().appendTo(elem); } }); }); }); </script> – Matt Ludwig Feb 10 '15 at 21:01
  • Try inspecting page using developer tools while entering new record. Do you see any errors/warnings in console? – 404 Feb 10 '15 at 21:02
  • This is the html code <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled 2</title> </head> <body> <h1>New Item</h1> <table cellpadding="5" cellspacing="15" > <tr > <td> <b>Area:</b> <font color="red">*</font> <br/> <span class="hillbillyForm" data-displayName="JPPNum"></span> </td> <td> <b>Legacy AFE:</b> <font color="red">*</font> <br><span class="hillbillyForm" data-displayName="Vendor"></span> </td> </tr> </table> </body> </html> – Matt Ludwig Feb 10 '15 at 21:03
  • none, any thoughts guys @jpollar – Matt Ludwig Feb 10 '15 at 21:37
3

SharePoint 2013 is using Client Side Rendering by default, so form controls are rendered on client side on some other internal javascript events. It is possible that jQuery.ready() handler is firing too early while controls are not rendered yet and that could be main problem.

My suggestion would be not to use jQuery.ready, where normal jsLink with CSR template override should be used. In this scenario CSR post render OnPostRender event should help you.

Here is sample how it could be used https://code.msdn.microsoft.com/office/Client-side-rendering-code-a52cf8a7

  • so the script would look like this??? <script src="//code.jquery.com/jquery-1.10.1.min.js"></script> <style type="text/css"> .ms-formtable {display:none;} </style><script type="text/javascript"> $(document).OnPostRender(function() { $("span.hillbillyForm").each(function() { displayName = $(this).attr("data-displayName"); elem = $(this); $("table.ms-formtable td").each(function(){ if (this.innerHTML.indexOf('FieldName="'+displayName+'"') != -1){ $(this).contents().appendTo(elem); } }); }); }); </script> – Matt Ludwig Feb 10 '15 at 21:18
  • Actually, no. You should look deeper at how you should use CSR in SharePoint 2013, here is more examples code.msdn.microsoft.com/office/… . I would also recommend not to use Content Editor Web Part but to use JSLink for new form web part zimmergren.net/technical/… These links should help you if you are new to CSR in SharePoint – ECM4D Feb 10 '15 at 21:23
  • I cant find jslink, im not sure why my original code is not working, I tried it on other SharePoint sites and it works fine, but with this site it isn't working. – Matt Ludwig Feb 10 '15 at 21:31
  • If you do not want to use CSR, you could try to turn off CSR and use server side rendering for the web part. Go to the web part settings and switch to Server side rendering. Go to the new form web part settings and choose "Server render" social.msdn.microsoft.com/Forums/getfile/268013 – ECM4D Feb 10 '15 at 21:38
  • I don't see that option to turn off csr tinypic.com/r/291mb1j/8 – Matt Ludwig Feb 10 '15 at 21:42

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.