Description:

SPUtility.js is a JavaScript library used to make modifications to SharePoint's list forms (NewForm.aspx and EditForm.aspx in a survey, custom list or library). This library depends on Prototype.js. SPUtility.js works with SharePoint 2010 and SharePoint 2007.

Features:
  • Set or get field values in Document Libraries, all sorts of List forms (custom lists, issues, etc), and survey
  • Make a field read only
  • Hide a field from view
  • No server side code to deploy!
This can be used for:
  1. Preventing a user from selecting a value when an item is initially created (ex: Status must be PENDING when the item is created)
  2. Hiding fields from a submitter but allowing the field to be edited (or vice versa).
  3. Autopopulating the form using a URL with query parameters

Keep in mind that SPUtility.js and documentation are still a work in progress... and that it won't work in every situation. For example, it won't work with:
  1. External list forms (working on a fix 4/22/2012)
  2. Forms that have been customized using Infopath
  3. Certain fields, see the matrix of supported fields

If you do find something that you would like supported or isn't quite working, please don't hesitate to post a Discussion.

See the Documentation for the matrix of supported fields and API documentation. Browse the Changelog to see the list of updates.

Installation

To use the library, you can just upload SPUtility.js and prototype.js into a document library and put a Content Editor Web Part with some JavaScript code on whichever page you want to modify! Detailed instructions are on the Installation page.

Usage Examples:

Set a Text field's value

SPUtility.GetSPField('Title').SetValue('Hello world!');

144458

Set a Text field's value and make it read only

SPUtility.GetSPField('Title').SetValue('Hello world!').MakeReadOnly();

144459

Make a Choice field read only

Before
144471

SPUtility.GetSPField('Status').MakeReadOnly();

After
144468

Set a People field and/or Make it Read Only

SPUtility.GetSPField('Assigned To').SetValue('Menke, Kit');

152982

SPUtility.GetSPField('Assigned To').MakeReadOnly();

152983

Hide a field from view

Before
144469

SPUtility.GetSPField('% Complete').Hide();

After
144470

See the Documentation for more information.

Last edited Apr 24, 2012 at 2:41 AM by KitMenke, version 40