April 26, 2011 Update: Version 0.8 released! See the
Changelog or the
post on my blog for more info.
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 has been tested in SharePoint 2007 with WSS 3.0 and MOSS (untested in SharePoint 2010 but reported as working by some users).
This library and documentation is still a work in progress, so any
feedback is greatly appreciated.
Features:
- Set or get field values
- Make a field read only
- Hide a field from view
- No server side code to deploy!
This can be used for:
- Preventing a user from selecting a value when an item is initially created (ex: Status must be PENDING when the item is created)
- Hiding fields from a submitter but allowing the field to be edited (or vice versa).
- Autopopulating the form using a URL with query parameters
See the
Documentation for the matrix of supported fields and API documentation. Browse the
Changelog to see the list of updates.
Usage Examples:
Set a Text field's value
SPUtility.GetSPField('Title').SetValue('Hello world!');
Set a Text field's value and make it read only
SPUtility.GetSPField('Title').SetValue('Hello world!').MakeReadOnly();
Make a Choice field read only
Before
SPUtility.GetSPField('Status').MakeReadOnly();After
Set a People field and/or Make it Read Only
SPUtility.GetSPField('Assigned To').SetValue('Menke, Kit');
SPUtility.GetSPField('Assigned To').MakeReadOnly();
Hide a field from view
Before
SPUtility.GetSPField('% Complete').Hide();After
See the
Documentation for more information.
Installation
To use the library, you'll need to upload SPUtility.js and prototype.js into SharePoint (a document library perhaps) 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.