-->

SharePoint CSOM Validate People Picker fields

Get SharePoint People Picker Value using Java Script


var PickerPerson = getPickerInputElement("ff13"); // Here ff13 is your people picker control ID

function getPickerInputElement(identifier) {
var tags = document.getElementsByTagName('DIV');
for (var i=0; i < tags.length; i++) {
var tempString = tags[i].id;
if ((tempString.indexOf(identifier) > 0) && (tempString.indexOf('UserField_upLevelDiv') > 0))        {
var innerSpans = tags[i].getElementsByTagName("SPAN");
for(var j=0; j < innerSpans.length; j++) {
if(innerSpans[j].id == 'content') {
return innerSpans[j].innerHTML;
}
}
}
}
return null;
}

Validate and compare the people picker values..

<script type="text/javascript">

function PreSaveAction(){

var OwnerVal = getPickerInputElement("ff4");
var ManagerVal = getPickerInputElement("ff5");
if(OwnerVal == ManagerVal){
alert("Please enter different names.");
return false;
}
else{
return true;
}
}

function getPickerInputElement(identifier) {
var tags = document.getElementsByTagName('DIV');
for (var i=0; i < tags.length; i++) {
var tempString = tags[i].id;
if ((tempString.indexOf(identifier) > 0) && (tempString.indexOf('UserField_upLevelDiv') > 0)){
var innerSpans = tags[i].getElementsByTagName("SPAN");
for(var j=0; j < innerSpans.length; j++) {
if(innerSpans[j].id == 'content') {
return innerSpans[j].innerHTML;
}
}
}
}
return null;
}

</script>

0 comments: