Saturday 5 July 2014

Read Only People Picker Fields in SharePoint List Forms

Introduction 
How to make a SharePoint List Column (form field) read only. There are questions on disabling (or making read-only) People Picker and Lookup Fields in SharePoint List Forms. Here I'm sharing the jQuery scripts to disable People Picker / Lookup fields in SharePoint list forms (EditForm.aspx).

Code
<script language="javascript" src="/JSLibrary/jquery-1.9.0.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function () {
var control = $("textarea[title='People Picker']")[0];
/* Detect browser*/
        if (navigator.appName == 'Microsoft Internet Explorer') {
        control.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.childNodes[1].style.display ="none";
        }
        else {
        control.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.childNodes[2].style.display ="none";
        }
var innerHtml = control.parentNode.parentNode.innerHTML;
control.parentNode.style.display = "none";
control.parentNode.parentNode.parentNode.parentNode.parentNode.innerHTML = control.parentNode.parentNode.parentNode.parentNode.parentNode.innerHTML + "<span class='fieldsTitle'>"+ $('.ms-inputuserfield #content').text() + "</span>";
});
</script>
 
Before this jQuery the People Picker was like this:         

People Picker       

People Picker test                                    
 
Summary
In this article we explored a disabled/read-only people picker field and also determining whether they work in every browser.

No comments:

Post a Comment

SharePoint 2013 - Uploading Multiple Attachments To The New Item On List Using JSOM And REST API

  Introduction In this article, we will explore how we can attach multiple attachments to the new item on list using JSOM and REST API. Ther...