Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@phillipharding
Created May 31, 2014 23:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phillipharding/fc870e493ece4453dc66 to your computer and use it in GitHub Desktop.
Save phillipharding/fc870e493ece4453dc66 to your computer and use it in GitHub Desktop.
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