Forum Discussion
Cardinal_Night
Nov 19, 2019Brass Contributor
How to set the default for a pnp.sp people picker
I want a pnp.sp people picker to auto populate with the logged in user. Here's the render and the people picker: <PeoplePicker
context={this.props.context}
personSelectionLimit={1}
grou...
O365Developer
Nov 20, 2019Brass Contributor
Hi,
I feel you are setting the state of the
LoggedInUserPPDefaultItems
in the
_loggedInUser
method which will be called onChange.
So it wont get prepopulated ,when you load the form ,However is it getting populated when you focus or doing a key press ,as that will trigger onchange.
Remember setState is async
Cardinal_Night
Nov 27, 2019Brass Contributor
O365Developer I think that you are correct but I'm not sure how to force the people picker to change on render. How would I do this?
- Guruprasad1380Apr 26, 2020Copper ContributorHow did you resolve ur issue ? Even i m trying to default users.. basically i get more than 5 users email from webservice, always these people new means (info wont be available in user information list) its a hidden people picker would like to prepopulate and save the item.. any idea how do i auto bind and trigger change event and capture usersid list so i can create item with the people picker column in the list?
- Carlos_MarinsApr 27, 2020Iron Contributor
Hey Guruprasad1380,
I was able to get the default user using its title as the key for the defaultSelectedUsers property. In my componentDidMount, I get the user using the sp.web.currentUser.get() method, store it in the state and then pass [this.state.me.Title] to the defaultSelectedUsers property of the picker. Let me know if it doesn't work for you.
Regards
- O365DeveloperDec 02, 2019Brass Contributor
Hi THomas,
You need to set the state of
LoggedInUserPPDefaultItems
to the current user values ,in the getUser() method which is invoked from componentDidMount() if I`m not wrong