Skip to main content

How to restrict multiple users for a people picker field in SharePoint 2013 form using script?

In this post, I will explain how to restrict multiple users on a people picker field in a SharePoint Form (NewForm or EditForm).

Firstly, we need to get the people picker field id



Use the below code and set the AllowMultipleUsers to false

var pp;

 SP.SOD.executeFunc('clientpeoplepicker.js', 'SPClientPeoplePicker', function () {

pp = SPClientPeoplePicker.SPClientPeoplePickerDict["UserName_xxxxxxx_$ClientPeoplePicker"];

 pp.AllowMultipleUsers = false;

        });

Another way is to get the count of users in the people picker field and restrict the save on PreSaveAction()

TotalUserCount will give the number of users in the peoplepicker field.

function PreSaveAction() {

    var count = pp.TotalUserCount;

    if (count > 1) {
        alert("Multiple users in people picker field");
        return false;
    }
    return true;
}

Comments