Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

how to place JS-code to NewForm.aspx of a list in SharePoint 2013 APP.

In sharepoint 2010 we can use this list definition to add JS:

<List ...>
  <MetaData>
    ...
    <Form Type="NewForm" Url="NewForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" UseDefaultListFormWebPart="False">
        <WebParts>
          <AllUsersWebPart WebPartZoneID="Main" WebPartOrder="1">
            <![CDATA[ 
            <WebPart xmlns="http://schemas.microsoft.com/WebPart/v2"
                xmlns:sfwp="http://schemas.microsoft.com/WebPart/v2/SimpleForm">
              <Assembly>Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>                         
              <TypeName>Microsoft.SharePoint.WebPartPages.SimpleFormWebPart</TypeName>
              <FrameType>None</FrameType>
              <Title>JS1</Title>
              <sfwp:Content>ANY HTML YOU NEED HERE
              </sfwp:Content>
            </WebPart>
            ]]>
          </AllUsersWebPart>
          <AllUsersWebPart WebPartZoneID="Main" WebPartOrder="2">
            <![CDATA[
            <WebPart xmlns="http://schemas.microsoft.com/WebPart/v2">
              <Assembly>Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>                         
              <TypeName>Microsoft.SharePoint.WebPartPages.ListFormWebPart</TypeName>
              <PageType>PAGE_NEWFORM</PageType>
            </WebPart>
            ]]>
          </AllUsersWebPart>
        </WebParts>
      </Form>
    </Forms>
  </MetaData>
</List>

How to do the same for Sharepoint 2013?

share|improve this question

3 Answers 3

From the Ribbon click on List -> Form Web Parts -> Default New Form

enter image description here

Click on Add a Web Part -> Media and Content -> Content Editor

Edit the Content Editor web part and put in the link to the JavaScript file

  • I store the js files at /SiteAssets/js/
  • From a sub-site you can link by using: ../SiteAssets/js/customjs.js
  • Make sure that the js file is formatted using html script tags
share|improve this answer
    
how to do this in xml? –  Pantani Aug 22 '14 at 8:59

What exactly are you trying to do with the JS? Is it for a specific column or for the whole form? There are some new things, but it depends on what you are actually trying to do. If it's for a specific column, there's a new JSLink attribute for a that lets you add JS to the column and change how it's rendered in all locations, but that is specific to the column. It would allow you to do something like implement a cascading selection for a column, something quite tricky to do and would only work on a specific form... this new way lets you control it for everything.

share|improve this answer

If you are using the default forms JS link is a great option.

There are a couple of other ways.

One is to edit the form page and add a Script Editor web part and add your javascript to the page. Very similar to the content part mentioned in this thread, but IMO better.

How to Use the Script Editor Web Part in SharePoint 2013 http://community.bamboosolutions.com/blogs/sharepoint-2013/archive/2013/05/20/how-to-use-script-editor-web-part-in-sharepoint-2013.aspx

You can also create a new custom form using SharePoint Designer and place the javascript directly in the form file.

How to Create Custom Forms Using SharePoint Designer 2013 http://community.bamboosolutions.com/blogs/sharepoint-2013/archive/2012/09/20/how-to-create-custom-forms-using-sharepoint-designer-2013.aspx

Then add your script block to the form by editing it with SharePoint Designer 2013.

<script type="text/javascript">
        $(document).ready(function()
          {
             javascript here....
          }
</script>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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