Get deleted names or entries from SharePoint 2010 format People Picker control on list forms using JavaScript or JQuery.
Here we have to get values from the people picker at OnLoad and PreSaveAction and we have to get the values and set the values as below.
/* */ var onloadViewerNames = []; var presaveViewerNames = []; jQuery(document).ready(function () { onloadViewerNames = getPickerInputElement("ff2"); // Get Viewer Names on load }); function PreSaveAction() { presaveViewerNames = getPickerInputElement("ff2"); // Get Viewer Names on pre save var getDeletedViewer = $(onloadViewerNames).not(presaveViewerNames).get(); var delvalues= ""; if(getDeletedViewer.length){ for (var i=0; i < getDeletedViewer.length; i++) { delvalues += getDeletedViewer[i] + "; "; } setPickerInputElement("ff6", delvalues) } return true; } // Get Users/Names from the Poeple Picker function getPickerInputElement(identifier) { var tags = document.getElementsByTagName('DIV'); var returnval = []; 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; returnval.push(innerSpans[j].innerHTML); } } } } return returnval; } // Set Deleted Users into another People Picker function setPickerInputElement(identifier, value) { var tags = document.getElementsByTagName('DIV'); for (var i=0; i < tags.length; i++) { var tempString = tags[i].id; //alert('tags[' + i + '].id = ' + tempString); if ((tempString.indexOf(identifier) > 0) && (tempString.indexOf('UserField_upLevelDiv') > 0)){ //alert('HIT for ' + identifier + ' id=' + tags[i].id + ' value=' + tags[i].value); tags[i].innerHTML = value; break; } } }
0 comments: