4

I want to create a custom people picker that picks people from a custom list. I have a list called Employees and another list called Vacation and in this list I want to create a people picker that picks items from Employees list.

In internet I found a picture

enter image description here

this is exactly what i want to do.

How can I make this?

Thanks

2

You have added a SharePoint online and SharePoint Enterprise in your tag ! so I am confused!

Anyway, in case of you are using a SharePoint server (on-prem), you can create a custom field type based on your requirements, you can find an example at Creating a Custom Field Type for SharePoint

Also, based on your attached image in your question, Fortunately, I found a free one that may be matched your requirement, it's Lookup Field with Picker 2010

enter image description here

It's for SharePoint 2010 that should be worked for SharePoint 2013 after upgrading the solution by doing the following:

enter image description here

  • The upgrade will be completed without any errors and a little warning

  • Make sure that the Site URL has been changed to your site that you need to deploy the solution

  • Deploy the solution.
  • Yes sir I am using sharepoint server, let me try this – Nderon Hyseni Dec 17 '16 at 11:49
6

You can use jquery autocomplete to bind the people values to a custom input tag. Try it as below:

<input id="myAutoCompleteSearch" type="text" />

The autocomplete code would look something as below:

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

$.ajax({
url: "https://sitecollectionurl//_api/web/lists/GetByTitle('Employees')/items?$select=Title",
type: 'GET',
dataType: 'json',
async: false,
headers: requestHeaders,
success: function (data) {
    $.each(data.d.results, function (i, result) {
      if(result.Title) {
        //push the people value 
         myData.push(result.Title);
      }   
    });

    myDataSource(myData);


},
error: function ajaxError(response) {
    console.log(response.status + ' ' + response.statusText);
}
});

function myDataSource(myData){
$('#myAutoCompleteSearch').autocomplete({
source: myData,
minLength: 3
});
}
  • +1... I take my answer back :) this should be right way to do it..!!! – Siddharth Vaghasia Dec 16 '16 at 11:26
2

ideally this is kind of cascading dropdowns, you can use lookup column, though it will not come as people picker field, it will be drop down.

If you are still looking for custom people picker, thinking out loud you can get started with below...please note it is just to give you an idea, you might have to think this in details like in which way use will search putting name, account name, domain\username, and other combinations...

Create a input text control using html, add a img button next to input control.

<input type="text" name="person" id="custompeoplepicker"> 
<img src="1231232.jgp" id="imgbutton"> </img> 

bind a event on click of img button,

$( "#imgbutton" ).click(function() {
var inputPeople= $( "#custompeoplepicker" ).val();

// write custom code to retrive items form that list

$().SPServices({
        operation: "GetListItems",
        async: false,
        listName: "Employees",
        CAMLQuery: "<Query><Where><Eq><FieldRef Name='Employee' /><Value Type='Choice'>" + deparmentid + "</Value></Eq></Where></Query>", // 
        CAMLViewFields: "<ViewFields>  <FieldRef Name='Employee' /> </ViewFields>", //Fetch other fields which you want.
        completefunc: function (xData, Status) {
          $(xData.responseXML).SPFilterNode("z:row").each(function() {
           $( "#custompeoplepicker" ).val( $(this).attr("ows_Employee"))
           found = true;
          });
          if(!found) {//show error message...not found}
        }
      });
});
2

Create a Sharepoint group and put the people in it. Create a new user site column and under the option choose from, instead of all users, pick your newly created group. Use your new site column in the vacation list Grab a cup of coffee ;)

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.