Add the new SPFindPeoplePicker function as shown in this post:
http://sympmarc.com/2012/04/22/working-with-sharepoint-people-pickers-with-jquery-a-new-function-called-findpeoplepicker/
I've made improvements since then.
// Find a People Picker in the page
// Returns references to:
// row - The TR which contains the People Picker (useful if you'd like to hide it at some point)
// contents - The element which contains the current value
// currentValue - The current value if it is set
// checkNames - The Check Names image (in case you'd like to click it at some point)$.fn.findPeoplePicker = function(options) {
$.fn.findPeoplePicker = function(options) {
var opt = $.extend({}, {
peoplePickerDisplayName: "", // The displayName of the People Picker on the form
valueToSet: "", // The value to set the People Picker to. Should be a string containing each username or groupname separated by semi-colons.
checkNames: true // If set to true, the Check Names image will be clicked to resolve the names
}, options);
var opt = $.extend({}, {
peoplePickerDisplayName: "", // The displayName of the People Picker on the form
valueToSet: "", // The value to set the People Picker to. Should be a string containing each username or groupname separated by semi-colons.
checkNames: true // If set to true, the Check Names image will be clicked to resolve the names
}, options);
var thisRow = $("nobr").filter(function() {
// Ensures we get a match whether or not the People Picker is required (if required, the nobr contains a span also)
return $(this).contents().eq(0).text() == opt.peoplePickerDisplayName;
}).closest("tr");
var thisContents = thisRow.find("div[Title='People Picker']");
var thisCheckNames = thisRow.find("img[Title='Check Names']:first");
if(opt.valueToSet.length > 0) thisContents.html(opt.valueToSet);
if(opt.checkNames) thisCheckNames.click();
var thisCurrentValue = thisContents.text().trim();
// Parse the entity data
var dictionaryEntries = [];
thisRow.find("div[title='People Picker'] > span").each(function() {
var thisData = $(this).find("div:eq(1)").attr("data");
var arrayOfDictionaryEntry = $.parseXML(thisData);
$xml = $(arrayOfDictionaryEntry);
var dictionaryEntry = {};
$xml.find("DictionaryEntry").each(function() {
var key = $(this).find("Key").text();
var value = $(this).find("Value").text();
dictionaryEntry[key] = value;
});
dictionaryEntries.push(dictionaryEntry);
});
return {row: thisRow, contents: thisContents, currentValue: thisCurrentValue, checkNames: thisCheckNames, dictionaryEntries: dictionaryEntries};
}
Comments: Mattias: I've copied your comment into a Discussion and added a question: http://spservices.codeplex.com/discussions/402258 M.
http://sympmarc.com/2012/04/22/working-with-sharepoint-people-pickers-with-jquery-a-new-function-called-findpeoplepicker/
I've made improvements since then.
// Find a People Picker in the page
// Returns references to:
// row - The TR which contains the People Picker (useful if you'd like to hide it at some point)
// contents - The element which contains the current value
// currentValue - The current value if it is set
// checkNames - The Check Names image (in case you'd like to click it at some point)$.fn.findPeoplePicker = function(options) {
$.fn.findPeoplePicker = function(options) {
var opt = $.extend({}, {
peoplePickerDisplayName: "", // The displayName of the People Picker on the form
valueToSet: "", // The value to set the People Picker to. Should be a string containing each username or groupname separated by semi-colons.
checkNames: true // If set to true, the Check Names image will be clicked to resolve the names
}, options);
var opt = $.extend({}, {
peoplePickerDisplayName: "", // The displayName of the People Picker on the form
valueToSet: "", // The value to set the People Picker to. Should be a string containing each username or groupname separated by semi-colons.
checkNames: true // If set to true, the Check Names image will be clicked to resolve the names
}, options);
var thisRow = $("nobr").filter(function() {
// Ensures we get a match whether or not the People Picker is required (if required, the nobr contains a span also)
return $(this).contents().eq(0).text() == opt.peoplePickerDisplayName;
}).closest("tr");
var thisContents = thisRow.find("div[Title='People Picker']");
var thisCheckNames = thisRow.find("img[Title='Check Names']:first");
if(opt.valueToSet.length > 0) thisContents.html(opt.valueToSet);
if(opt.checkNames) thisCheckNames.click();
var thisCurrentValue = thisContents.text().trim();
// Parse the entity data
var dictionaryEntries = [];
thisRow.find("div[title='People Picker'] > span").each(function() {
var thisData = $(this).find("div:eq(1)").attr("data");
var arrayOfDictionaryEntry = $.parseXML(thisData);
$xml = $(arrayOfDictionaryEntry);
var dictionaryEntry = {};
$xml.find("DictionaryEntry").each(function() {
var key = $(this).find("Key").text();
var value = $(this).find("Value").text();
dictionaryEntry[key] = value;
});
dictionaryEntries.push(dictionaryEntry);
});
return {row: thisRow, contents: thisContents, currentValue: thisCurrentValue, checkNames: thisCheckNames, dictionaryEntries: dictionaryEntries};
}
Comments: Mattias: I've copied your comment into a Discussion and added a question: http://spservices.codeplex.com/discussions/402258 M.