SPUtility

We have seen how to check if user belongs to a particular sharepoint group or not in Part 1. Let’s see how to show/hide/disable sharepoint fields using SPUtility.

About SPUtility

It is a javascript library used to

  • set or get field values
  • Show or hide fields
  • Make the fields as read-only

It is compatible with SharePoint 2010, SharePoint 2013, O365 and MOSS 2007.

Prerequisite:

Download the below files, copy and save it as .js

To set values when form is loaded:

_spBodyOnLoadFunctionNames.push("Default");
function Default()
{
SPUtility.GetSPField('Title').SetValue('Hello');
}

You can also use in jquery as:

$(document).ready(function()
{
SPUtility.GetSPField('Title').SetValue('Hello');
});

To get the values:

$(document).ready(function()
{
var status = SPUtility.GetSPField('Status').GetValue();
});

To show, hide and disable the fields:

$(document).ready(function()
{
SPUtility.GetSPField('Status').Show();
SPUtility.GetSPField('Status').Hide();
SPUtility.GetSPField('Status').MakeReadOnly();
});

Insert these codes as per your requirement into previous posted code.

Advertisements

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s