1

Problem:

When using a non-default form for new or editing items the auto-complete function for the people field is lost. According to my research Sharepoint reverts back to an earlier versions display style.

Default List
enter image description here

v.s.

Custom List
enter image description here

Desired Outcome:

Auto-complete to work for custom lists as well as default lists.

Solution: Can be found at: http://spobject.blogspot.com.au/2013/02/clientpeoplepicker-in-sharepoint-2013.html.

However I'm unsure of where to add each piece of code.

Could somebody explain where to insert these spinets of code?

2

In your custom form use Client Side Rendering and render the desired people picker column with the default template, i.e. SPClientPeoplePickerCSRTemplate. This will automatically render your column as you desire.

Source

0

There is a much easier way to implement a people picker in Javascript. You can use Rest Api to do this as well.


<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script>
function search(request,response) {   
var restSource = "http://siteUrl/_api/SP.UI.ApplicationPages.ClientPeoplePickerWebServiceInterface.clientPeoplePickerSearchUser";
$.ajax( 
{
'url':restSource,
'method':'POST',
'data':JSON.stringify({
    'queryParams':{
        '__metadata':{
            'type':'SP.UI.ApplicationPages.ClientPeoplePickerQueryParameters'
        },
        'AllowEmailAddresses':true,
        'AllowMultipleEntities':false,
        'AllUrlZones':false,
        'MaximumEntitySuggestions':50,
        'PrincipalSource':15,            
        'QueryString':extractLast(request.term)
        //'Required':false,
        //'SharePointGroupID':null,
        //'UrlZone':null,
        //'UrlZoneSpecified':false,
        //'Web':null,
        //'WebApplicationID':null
    }
}),
'headers':{
    'accept':'application/json;odata=verbose',
    'content-type':'application/json;odata=verbose',
    'X-RequestDigest':$("#__REQUESTDIGEST").val()
},
'success':function (data) { 
    var d = data;
    var results = JSON.parse(data.d.ClientPeoplePickerSearchUser);
    console.log(results);
    if (results.length > 0) {
        response($.map(results, function (item) {
            return {label:item.DisplayText,value:item.DisplayText}
        }));
    }         
},
'error':function (err) { 
    console.log(JSON.stringify(err)); 
}
}
);
}
function split( val ) {
return val.split( /;/ );
}
function extractLast( term ) {
return split( term ).pop();
}
$("document").ready(function(){
$(".ms-inputuserfield").autocomplete({
minLength: 1,
source: search,
select: function( event, ui ) {
            var terms = split( $(this).text() );
            terms.pop();
            terms.push( ui.item.value );
            terms.push( "" );
            $(this).text(terms.join( ";" ));
            return false;
            }
});
});
</script>

Source: link.

  • Am I correct to say: 1. I simply insert both sections of code from this article into the script tags at the bottom of the custom form. 2. Change type to ClientPeoplePicker. – user3462522 Jul 23 '15 at 5:32
  • You'll have to define a jquery UI autocomplete textbox. Updated my answer. Please check. – Akhoy Jul 23 '15 at 6:01
  • Just to clarify what I need to do, and check if I am missing something. Do I add these two pieces of code to the script tags at the bottom of the form aspx. Then it will work? – user3462522 Jul 24 '15 at 1:42
  • Yes, you can copy the whole code. I've modified it to include it under 1 script tag. I'e tested this and think it should work. You just have to modify the siteUrl part in the REST api code. This code will also work for multiple users but it won't resolve the users. All you have to do is to press that resolve icon after adding the users to resolve them. That said, I still think @TaranGoel's answer is better. Your choice. :) – Akhoy Jul 24 '15 at 18:44
0

I have been able to successfully create a non-default 'NewForm2' file for a list using PowerShell and still retain the original OOTB ability of the people picker to autocomplete.

Like many others I found that creating a new list form using SPD stripped the OOTB people picker for an older version which did not perform as expected. How I solved this problem was to simply not use SharePoint Designer. I used PowerShell to create a new form for the specified list and was pleased to find that the OOTB autopicker functionality for the people picker once again worked as expected. The dropdown populated with the pool of results and I was also able to successfully save the form with the people picker value.

$url = "http://SiteURL/"

$listname = "NameOfList"
$web = get-spweb $url 
$list = $web.lists[$listname]
$files = $list.rootfolder.files

$newformurl = $list.RootFolder.ServerRelativeUrl + "/NewForm2.aspx"

$newform = $files.add($newformurl, [Microsoft.SharePoint.SPTemplateFileType]::FormPage)

$wpm = $newform.GetLimitedWebPartManager([System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)

$lfw = new-object ([Microsoft.SharePoint.WebPartPages.ListFormwebpart])

$ilist = [Microsoft.SharePoint.WebPartPages.IListWebPart]($lfw)

$ilist.ListId = $list.id
$ilist.PageType = [Microsoft.SharePoint.PAGETYPE]::PAGE_NEWFORM;

$wpm.AddWebPart($lfw, "Main", 1)

$list.DefaultNewFormUrl = $newformurl

$list.update()

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.