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.
As of March 2013, a
jQuery version is in the works, your feedback is appreciated!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:
- 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
Keep in mind that SPUtility.js and documentation are still a work in progress... and that it won't work in every situation.
It currently will NOT work with:
- External list forms (working on a fix 4/22/2012)
- Forms that have been customized using Infopath
- Certain (weird) 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!');
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.