5

I would like to know if there is a way to generate a SharePoint 2010 People picker control just with JavaScript. Imagine that I am doing a Windows 8 App, I would like to create that control dynamically. Remember JavaScript only!

Thanks

4 Answers 4

4

OK, finally got. After long hours looking at the ugliest HTML/JS even written and short short periods of insanity, I add an idea that I don't totally like and it isn't the best, but at this point I don't f***ing care. I just want to get over this.

So, I simple create a basic .aspx page with the follwing code:

<%@ Page Language="C#" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<body>
    <form id="SdfPeoplePickerForm" runat="server">   
        <SharePoint:PeopleEditor ID="SdfPeoplePicker" runat="server" SelectionSet='User,SecGroup,SPGroup' />
    </form>
</body>
</html>

I moved this page to _layouts folder on my SharePoint farm and name it PeoplePicker.aspx. Then on my page/app I just added a pointing to that aspx. That's it. I know it's ugly as hell and is clearly not the best solution, but at least it solves my problem. If some day my brain becomes strong enough to handle the craziness behind the peoplePicker generated code, I will share the proper solution. Thanks for your help eirikb

1
  • By the way, any comments or suggestions are more then welcome! Commented Oct 3, 2012 at 20:00
1

You can inject the correct markup directly into the DOM, I have tested this myself and it works perfectly. The People Picker does not depend on any document ready or similar. All you have to do is follow the correct markup and include the file entityeditor.js which you will find in the layouts folder.

Another option is to use the Client Object Model to mimic the behavior, and use OpenPopUpPage on /_layouts/Picker.aspx. You might need the whole query string for PickerDialogType, but by opening the original dialog you will see what query strings you must include.

7
  • So you just had to create the proper HTML skeleton, include entityeditor.js and that's it? I check the HTML sent to generate a datepicker and it creates a bunch ridiculous JS functions like __Dialog__StupidIdName. So I was wondering how could you get this out of the box. Commented Oct 2, 2012 at 20:49
  • 1
    You mean the JS function arguments, not the functions themselves right? In any case yes I believe you could just trim those down, but make sure you update the ones with $ instead of _ as well
    – eirikb
    Commented Oct 3, 2012 at 5:05
  • 1
    Sorry you are right, I need to look into it
    – eirikb
    Commented Oct 3, 2012 at 5:17
  • 1
    Ok I see the functions, pretty stuff. I believe you have to extract and include these yourself. They are written directly out into the page (for example in NewForm.aspx). You also need to search/replace the names in all of them. I believe it should be possible to make these a bit more general though, so if you happen to do it maybe others would be interested
    – eirikb
    Commented Oct 3, 2012 at 5:23
  • 1
    It would be awesome if you put your code (or a solution) on codeplex/github/gitorious or similar. ❤
    – eirikb
    Commented Oct 3, 2012 at 13:57
1

I have a client side jQuery/SPServices/jQueryUI plugin that can do this for custom UI's. Take a look here:

http://paultavares.wordpress.com/2012/04/28/sharepoint-ui-widgets-upload-and-pickusers/

I use it today in a custom UI I created for some projects.

Paul.

4
  • Thanks Paul, I will also take a look at your solution. Obrigado! Commented Oct 3, 2012 at 21:12
  • It should be noted that at this point Paul T.'s solution does not resolve users outside of the existing site (the User Information List). Paul, if you implement that functionality then hopefully you will comment here.
    – Chloraphil
    Commented Oct 5, 2016 at 20:07
  • I stand corrected - it looks like it does so now. Paul, my apologies!
    – Chloraphil
    Commented Oct 5, 2016 at 22:13
  • Sorry I did not get back to you yesterday. Glad you figured it out though. :)
    – Paul T.
    Commented Oct 7, 2016 at 1:49
1

Just add this to your ascx page but change the version and other necessary details.

<%-- _lcid="1033" _version="12.0.4518" _dal="1" --%>
<%-- _LocalBinding --%><%@ Page language="C#" MasterPageFile="~masterurl/default.master"    Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage,Microsoft.SharePoint,Version=12.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %><%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

finally add this tag

 <SharePoint:PeopleEditor ID="SdfPeoplePicker" runat="server" SelectionSet='User,SecGroup,SPGroup'/>
4
  • <SharePoint:PeopleEditor ID="SdfPeoplePicker" runat="server" SelectionSet='User,SecGroup,SPGroup'/>
    – SP.erby
    Commented Jan 14, 2016 at 2:47
  • <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %><%@ Import Namespace="Microsoft.SharePoint" %> <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    – SP.erby
    Commented Jan 14, 2016 at 2:50
  • <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    – SP.erby
    Commented Jan 14, 2016 at 2:50
  • edit your answer and include details that you have commented.... Comments are not meant for full-length code Commented Jan 14, 2016 at 4:15

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.