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
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
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.
$
instead of _
as well
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.
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'/>