Validate SharePoint people picker before Save.
Scenario: When user enters firstName LastName in people picker and click SharePoint save, without validating user.
Site shows error message
Reason : We have 30,000+ user and 5+ domains so request time-outs.
Fix : Ask user to validate people picker before save.
JavaScript :
function getPickerInputElement(identifier)
{
var tags = document.getElementsByTagName('DIV');
for (var i=0; i < tags.length; i++)
{
var tempString = tags[i].id;
if ((tempString.indexOf('UserField_upLevelDiv') > 0))
{
if(identifier == tempString)
{
var innerSpans = tags[i].getElementsByTagName("SPAN");
for(var j=0; j < innerSpans.length; j++)
{
if(innerSpans[j].id == 'content')
{
return innerSpans[j].innerHTML;
}
}
}
}
}
return "";
}
/* SharePoint 2010 calls below function on save click */
function PreSaveAction()
{
var returnValue = true;
var requestorPerson = getPickerInputElement('<DIV ID OF PEOPLE PICKER>');
if(!requestorPerson || requestorPerson == "")
{
returnValue = false;
alert(' <FIELD> is not validated. Please validate.\n Enter "Email Address" or "Domain\LANID" and click validate button next to text box.');
}
return returnValue
}
/******************** END OF JAVA SCRIPT ******************/
Thanks :-)
ReplyDelete