Pergunta

Existe uma maneira de acionar uma função JS quando um seletor de pessoas é concluído e encontra um usuário?Estou desenvolvendo um aplicativo SharePoint 2013 usando o padrão de desenvolvimento do lado do cliente.

Obrigado pela sua sugestão. Tentei adicionar o OnUserResolvedClientScript ao controle da seguinte maneira, mas não está funcionando, não tenho certeza se posso adicioná-lo dessa maneira?

// First we need to get the selected user from the person selected in the people picker
$(document).ready(function () {

// Specify the unique ID of the DOM element where the
// picker will render.
initializePeoplePicker('employeePickerSpan');});

// Render and initialize the client-side People Picker.
function initializePeoplePicker(peoplePickerElementId) {
// Create a schema to store picker properties, and set the properties.
var schema = {};
schema['PrincipalAccountType'] = 'User,DL,SecGroup,SPGroup';
schema['SearchPrincipalSource'] = 15;
schema['ResolvePrincipalSource'] = 15;
schema['AllowMultipleValues'] = true;
schema['MaximumEntitySuggestions'] = 50;
schema['OnUserResolvedClientScript'] = 'MyPickerUserResolved';
schema['Width'] = '250px';

// Render and initialize the picker. 
// Pass the ID of the DOM element that contains the picker, an array of initial
// PickerEntity objects to set the picker value, and a schema that defines
// picker properties.
this.SPClientPeoplePicker_InitStandaloneControlWrapper(peoplePickerElementId, null, schema);

}

function MyPickerUserResolved(topElementId,  MyPickerUserResolvedusers) {
// users is set to GetAllUserInfo()
// Get the people picker object from the page.
var employeePicker =    this.SPClientPeoplePicker.SPClientPeoplePickerDict.employeePickerSpan_TopSpan;

// Get information about all employees.
var employees = employeePicker.GetAllUserInfo();
var employeeInfo = '';
for (var i = 0; i < employees.length; i++) {
    var employee = employees[i];
    for (var employeeProperty in employee) {
        employeeInfo += employeeProperty + ':  ' + employee[employeeProperty] + '<br>';
    }
}
$('#employeelineManager').html(employeeInfo);
}
Foi útil?

Solução

Na criação do ClientPeoplePicker você pode definir o OnUserResolvedClientScript propriedade para uma função como:

function MyPickerUserResolved (topElementId, users) { 
    // users is set to GetAllUserInfo()
} 

Outras dicas

Você poderia usar algum jQuery para identificar quando o campo na página muda.O DIV do seletor de pessoas terá texto simples para itens ainda não verificados (ou seja,se você digitou um nome, mas não clicou em verificar nomes) e um intervalo para cada item verificado.

Aqui estão alguns exemplos de como monitorar um DIV como esse: https://stackoverflow.com/questions/4979738/fire-jquery-event-on-div-change

Esta função funciona no Internet Explorer para mim:

function MyPickerUserResolved (topElementId, users) {                    
  //prevent users == null
  if(users.length != 0){
    var UserManager = users[0].Description;
    alert(UserManager); // show message contains on user position 1;
  }
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a sharepoint.stackexchange
scroll top