Disable people picker column in New/Edit Form
The
following JQuery script can be used to achieve this. Please note ApproverName
is nothing but people picker field name.
<script type="text/javascript">
$(document).ready(function()
{
$('nobr:contains("ApproverName")').closest("td").next("td").attr("disabled", "disabled");
$("div[id$='_UserField_upLevelDiv']").attr("contentEditable",false);
$("span[id$='_UserField']").find("img").hide();
}
);
function PreSaveAction()
{
$('nobr:contains("ApproverName")').closest("td").next("td").removeAttr("disabled");
$("div[id$='_UserField_upLevelDiv']").attr("contentEditable",true);
$("span[id$='_UserField']").find("img").show();
return true;
}
</script>
Here the PreSaveAction is very important. If you did not include this function the value of the people picker column won't be saved in to the list. Before saving we are required to enable this control otherwise SharePoint will not be able read value from this control.
Source: http://www.rajsoftsys.com/sharepoint/?p=183
After adding this JQuery the control looks like below.
<script type="text/javascript">
$(document).ready(function()
{
$('nobr:contains("ApproverName")').closest("td").next("td").attr("disabled", "disabled");
$("div[id$='_UserField_upLevelDiv']").attr("contentEditable",false);
$("span[id$='_UserField']").find("img").hide();
}
);
function PreSaveAction()
{
$('nobr:contains("ApproverName")').closest("td").next("td").removeAttr("disabled");
$("div[id$='_UserField_upLevelDiv']").attr("contentEditable",true);
$("span[id$='_UserField']").find("img").show();
return true;
}
</script>
Here the PreSaveAction is very important. If you did not include this function the value of the people picker column won't be saved in to the list. Before saving we are required to enable this control otherwise SharePoint will not be able read value from this control.
Source: http://www.rajsoftsys.com/sharepoint/?p=183
After adding this JQuery the control looks like below.
Comments
Post a Comment