0

I want to set default selected user on people picker?

<NormalPeoplePicker
                onChange={this._onChange.bind(this)}
                onResolveSuggestions={this._onFilterChanged}
                getTextFromItem={(persona: IPersonaProps) => persona.primaryText}
                pickerSuggestionsProps={suggestionProps}
                className={'ms-PeoplePicker'}
                key={'normal'}
                itemLimit={1}
                defaultSelectedItems={()}


              />

How to use defaultSelectedItems? Thanks

3
  • You mean the current logged in user should be set as default in a people picker? Commented Oct 10, 2018 at 10:53
  • yes, the loged user should be set as default
    – maaa
    Commented Oct 10, 2018 at 10:59
  • I have added the code below in answers. Please don't forget to upvote and mark the answer as accepted in case it helped you! Commented Oct 11, 2018 at 17:48

1 Answer 1

0

You can achieve this using REST API:

$(document).ready(function () {

var userid = _spPageContextInfo.userId;

function GetUserLogin() {
var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/getuserbyid(" + userid + ")";

var requestHeaders = { "accept" : "application/json;odata=verbose" };

$.ajax({
  url : requestUri,
  contentType : "application/json;odata=verbose",
  headers : requestHeaders,
  success : QuerySuccess,
  error : QueryError
});
}

function QuerySuccess(data, request){
  //removes the claims encoding
  var loginName = data.d.LoginName.split('|')[1];
  $("div[title='PeoplePickerColumnName']").val(loginName);
}

function QueryError(error) {
  alert(error);
}

GetUserLogin();

});

Reference

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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