You did not specify a version of SharePoint, but the following explanation applies to SharePoint 2007 and was not confirmed in 2010.
The people selection value can be set by clicking the Check Names icon or the Browse icon.
If you click the Check Names icon, which is an anchor tag, the onclick event triggers a WebForm_DoCallback, which will asynchronously make an HTTP request to the SharePoint server to validate the name entered in the people collector.
The following is the signature of WebForm_DoCallback:
function WebForm_DoCallback(eventTarget, eventArgument, eventCallback, context, errorCallback, useAsync){ ... }
One of the WebForm_DoCallbacks arguments that interests you the most is the "eventTarget", a text area for selecting people. You will also be interested in "eventCallback" since the callback method is called after the async HTTP request is returned. In this case, it is the "EntityEditorHandleCheckNameResult (result, ctx)" defined in the js core.
The following is a definition of the EntityEditorHandleCheckNameResult function
function EntityEditorHandleCheckNameResult(result, ctx) { EntityEditorClearWaitCursor(ctx); EntityEditorCallback(result, ctx); }
Note that he delegates the processing of the event to the EntityEditorCallback method. This also happens if you click the Browse icon, which opens a dialog box for searching and selecting a user. The Browse icon obviously uses a different call stack, but since both of them rely on EntityEditorCallback, I will focus on this method since the solution works when you click Check Names or Browse.
To execute your code after calling EntityEditorCallback, you can use the following code:
var invokeAfterEntityEditorCallback = function(func) { var old__EntityEditorCallback = EntityEditorCallback; if (typeof EntityEditorCallback != 'function') { EntityEditorCallback = func; } else { EntityEditorCallback = function(result, ctx) { old__EntityEditorCallback(result, ctx); func(result, ctx); } } };
The following is a custom event handler for people that notifies the result and the identifier of the people selection area:
function onPeoplePickerFieldSet(result, ctx){ alert(result); alert(ctx); }
The following logic allows you to call the onPeoplePickerFieldSet method after the name of the people picker is verified or selected in the browse dialog box. Alternatively, you can call this statement in the document.ready event handler if you are using jQuery.
invokeAfterEntityEditorCallback(onPeoplePickerFieldSet);
The 'result' argument to the onPeoplePickerFieldSet method is an XML result that indicates a successful validation, as well as a username named quailified. The following XML example is the result of clicking the Check Names button:
<Entities Append="False" Error="" Separator=";" MaxHeight="3"> <Entity Key="HOLLOWAY\csteel" DisplayText="Craig Steel" IsResolved="True" Description="HOLLOWAY\csteel"> <ExtraData> <ArrayOfDictionaryEntry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <DictionaryEntry> <Key xsi:type="xsd:string">DisplayName</Key> <Value xsi:type="xsd:string">Craig Steel</Value> </DictionaryEntry> <DictionaryEntry> <Key xsi:type="xsd:string">Email</Key> <Value xsi:type="xsd:string"> csteel@holloway.net </Value> </DictionaryEntry> <DictionaryEntry> <Key xsi:type="xsd:string">SPUserID</Key> <Value xsi:type="xsd:string">16</Value> </DictionaryEntry> <DictionaryEntry> <Key xsi:type="xsd:string">PrincipalType</Key> <Value xsi:type="xsd:string">User</Value> </DictionaryEntry> </ArrayOfDictionaryEntry> </ExtraData> <MultipleMatches /> </Entity> </Entities>
The argument 'ctx' is the identifier of the text area of the people picker and can be used in jQuery selector instructions.
What is it!