Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Set the value of SharePoint People Picker Controls
(function(module,$) {
"use strict";
window.PD = window.PD || {};
PD.SP = PD.SP || {};
PD.SP.PeoplePicker = function() {
var
_module = {
Validate: ValidatePeoplePicker,
Set: SetPeoplePicker
};
return _module;
function ValidatePeoplePicker(pickerid) {
// click on check names
$("SPAN[id$='" + pickerid + "'] A[id$='" + pickerid + "_checkNames']").first().click();
},
function SetPeoplePicker(pickerid, key, append) {
var
a = (typeof append != "undefined" ? !!append : false).toString(),
xml = '';
a = a.charAt(0).toUpperCase() + a.slice(1);
xml = '<Entities Append="'+a+'" Error="" Separator=";" MaxHeight="3">'
+ CreatePeoplePickerEntityXml(key)
+ '</Entities>';
EntityEditorCallback(xml, pickerid, true);
ValidatePeoplePicker(pickerid);
},
function CreatePeoplePickerEntityXml(key) {
return '<Entity Key="' + key + '" DisplayText="" IsResolved="False" Description=""><MultipleMatches /></Entity>';
}
}();
})({ Name: 'SP-PeoplePicker' }, jQuery);
/* how to use */
// get the control id of a people picker using the field display name
var controlId = $('TD.ms-formlabel nobr:contains("Approval Manager")').parent().parent().next().find('span > span').attr('id');
// set the control value using either display names or loginnames
PD.SP.PeoplePicker.Set(controlId, 'bob;alice', true);
PD.SP.PeoplePicker.Set(controlId, 'pdogs\\bob;pdogs\\alice', false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.