I added 3 users in ClientPeoplePicker but when i am removing 1 or 2 users and saving the ClientPeoplePicker values. Still saving all 3 users. How to handle these removed users from ClientPeoplePicker? Can you suggest me.

  • share some of your code please – akbar ali Dec 29 '16 at 13:19

you can add validation to allow only one person to the people picker by using the following code in the submission button

  <script type="text/javascript">
    $("#btnsubmit").on("click", function(a) {
        if ($("#txtName").find('div.sp-peoplepicker-topLevel').find('.sp-peoplepicker-resolveList').children().length != 1) {
            alert("Please enter only one name");
            initializePeoplePicker("txtName"); //Reinitialise people picker again
        } else{
           saving code

Javascript Code:

var usr;
var contextDR;
var webDR;
var teamleaderarray = new Array();
$(document).ready(function ()  {
     SP.SOD.executeFunc('sp.js', 'SP.ClientContext', getusername); 

//initialize PeoplePicker div tag 
function initializePeoplePicker(peoplePickerElementId)  {
     var schema = {};
     schema['PrincipalAccountType'] = 'User,DL,SecGroup,SPGroup';
     schema['SearchPrincipalSource'] = 15;
     schema['ResolvePrincipalSource'] = 15;
     schema['AllowMultipleValues'] = true;
     schema['MaximumEntitySuggestions'] = 50;
     schema['Width'] = '222px'; 
     this.SPClientPeoplePicker_InitStandaloneControlWrapper(peoplePickerElementId, null, schema);

function getUserInfo1()  
     teamleaderarray = [];
     var peoplePicker = this.SPClientPeoplePicker.SPClientPeoplePickerDict.peoplePickerteamleaderDiv_TopSpan;
     var users = peoplePicker.GetAllUserInfo();
     var userInfo = '';
     for (var i = 0; i < users.length; i++)     
        var user = users[i];

function btnSave_Click() {

    //get users from peoplepicker 

    //create clientcontext object and create web object     
        contextDR = SP.ClientContext.get_current();
        webDR = contextDR.get_web();

    //get list
        var Lst = webDR.get_lists().getByTitle('listname');
   //create new item in list    
        var itemCreateInfo = new SP.ListItemCreationInformation();
        InListItem = Lst.addItem(itemCreateInfo);
        InListItem.set_item('Auditleader', teamleaderarray);                
        contextDR.executeQueryAsync(Function.createDelegate(this, this.submitsuccess), Function.createDelegate(this, this.submitfail)); 

body part:

<div id="peoplePickerteamleaderDiv"></div>
<input type="button" id="btnSave" value="Save" onclick="javascript: btnSave_Click();" />

use this js reference:


Using this code my peoplepicker run perfectly,

if any problem add comment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.