Code for Js

  1. (function($) {
  2. RegisterScriptFiles('clienttemplates.js');
  3. RegisterScriptFiles('clientforms.js');
  4. RegisterScriptFiles('clientpeoplepicker.js');
  5. RegisterScriptFiles('autofill.js');
  6. function RegisterScriptFiles(filename) {
  7. var scriptEle = document.createElement('script');
  8. scriptEle.setAttribute("type", "text/javascript")
  9. scriptEle.setAttribute("src", "/_layouts/15/" + filename);
  10. document.getElementsByTagName("head")[0].appendChild(scriptEle)
  11. }
  12. // Render and initialize the client-side People Picker.
  13. function initializePeoplePicker(eleId) {
  14. // Create a schema to store picker properties, and set the properties.
  15. var schema = {};
  16. schema['PrincipalAccountType'] = 'User,DL,SecGroup,SPGroup';
  17. schema['SearchPrincipalSource'] = 15;
  18. schema['ResolvePrincipalSource'] = 15;
  19. schema['AllowMultipleValues'] = true;
  20. schema['MaximumEntitySuggestions'] = 50;
  21. schema['Width'] = '280px';
  22. // Render and initialize the picker.
  23. // Pass the ID of the DOM element that contains the picker, an array of initial
  24. // PickerEntity objects to set the picker value, and a schema that defines
  25. // picker properties.
  26. this.SPClientPeoplePicker_InitStandaloneControlWrapper(eleId, null, schema);
  27. }
  28. function GetPeoplePickerValues(eleId) {
  29. var toSpanKey = eleId + "_TopSpan";
  30. var peoplePicker = null;
  31. // Get the people picker object from the page.
  32. //var peoplePicker = this.SPClientPeoplePicker.SPClientPeoplePickerDict.peoplePickerDiv_TopSpan;
  33. var ClientPickerDict = this.SPClientPeoplePicker.SPClientPeoplePickerDict;
  34. // Get the people picker object from the page.
  35. for (var propertyName in ClientPickerDict) {
  36. if (propertyName == toSpanKey) {
  37. peoplePicker = ClientPickerDict[propertyName];
  38. break;
  39. }
  40. }
  41. if (peoplePicker != null) {
  42. // Get information about all users.
  43. var users = peoplePicker.GetAllUserInfo();
  44. var userInfo = '';
  45. for (var i = 0; i < users.length; i++) {
  46. var user = users[i];
  47. userInfo += user['DisplayText'] + ";#";
  48. }
  49. return userInfo;
  50. } else return '';
  51. }
  52. $.fn.spPeoplePicker = function() {
  53. var eleId = $(this).attr('id');
  54. ExecuteOrDelayUntilScriptLoaded(function() {
  55. initializePeoplePicker(eleId);
  56. }, 'sp.core.js');
  57. };
  58. // Query the picker for user information.
  59. $.fn.getUserInfo = function() {
  60. var eleId = $(this).attr('id');
  61. var spUsersInfo = GetPeoplePickerValues(eleId);
  62. return spUsersInfo.slice(0, -2);
  63. }
  64. })(jQuery);
Procedure

Step 1

Save Above code as JS file and refer to it in your Program

Step 2

Call it by using the below function
  1. $(function() {
  2. $('#ppDefault').spPeoplePicker();
  3. });
Step 3

Create below div in your Html file
  1. <div id="ppDefault"></div>

Step 4

Add schema ['SharePointGroupID'] = (Group No(eg 7)); in function initializePeoplePicker(eleId) to Filter Users from Invidual Group....//(this if For only Members in the Group hav loaded in People Picker..)

i.e. schema['SharePointGroupID'] = 7;

Step 5

Create the .txt File using the above procedure, and include the hyperlink of Js created in step 1 and add Min.jss and relevant CSS

Step 6

Call this Html in your Sharepoint Page using Content Editor WebPart....

I hope I have helped someone.

Comments

Join the conversation! Your thoughts help the community grow.