none
Send alert when people picker change jquery

    Question

  • hi. good afternoon.

    Is there a jquery code with which you can send an alert when a user is introduced to my people picker?

    in a drop down I do it this way $("select[title='Geographical']").change(function() but in the people picker it does not work for me.

    In a drop I do it this way but in the people picker it does not work for me

    laureano Adriano

    Tuesday, February 14, 2017 6:49 PM

Answers

  • Hi,

    You can use the following code, which works fine in my environment:

    <script src="//code.jquery.com/jquery-3.1.0.min.js" type="text/javascript"></script>

    <script type="text/javascript">

    $(function(){

                var dispTitle = "<your People picker field name>";     

                var pickerDiv = $("[id$='ClientPeoplePicker'][title='" + dispTitle + "']");     

                var peoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict[pickerDiv[0].id];

                peoplePicker.OnValueChangedClientScript=function (peoplePickerId, selectedUsersInfo) {

                                        alert("inside OnValueChangedClientScript");

                };    

    });

    </script>

    Thanks,

    Dean Wang


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Wednesday, February 15, 2017 5:23 AM
    Moderator
  • Hi,

    SharePoint 2010 people picker is different from SharePoint 2013. You can try the following code:

    <script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
    
    <script type="text/javascript">
    
    $(function(){
    
                invokeAfterEntityEditorCallback(onPeoplePickerFieldSet);
    
    });
    
    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);
    
            }
    
        }
    
    };
    
    function onPeoplePickerFieldSet(result, ctx){
    
                alert("inside OnValueChangedClientScript");}
    
    </script>
    

    By the way, you can post in SharePoint 2010 forum next time :)

    Thanks,

    Dean Wang


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Thursday, February 16, 2017 9:16 AM
    Moderator

All replies

  • Hi,

    You can use the following code, which works fine in my environment:

    <script src="//code.jquery.com/jquery-3.1.0.min.js" type="text/javascript"></script>

    <script type="text/javascript">

    $(function(){

                var dispTitle = "<your People picker field name>";     

                var pickerDiv = $("[id$='ClientPeoplePicker'][title='" + dispTitle + "']");     

                var peoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict[pickerDiv[0].id];

                peoplePicker.OnValueChangedClientScript=function (peoplePickerId, selectedUsersInfo) {

                                        alert("inside OnValueChangedClientScript");

                };    

    });

    </script>

    Thanks,

    Dean Wang


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Wednesday, February 15, 2017 5:23 AM
    Moderator
  • Thank u very much  for u answer.

    The code does not work for, I comment u I am using SharePoint 2010 and my people picker is called GP Can you make me some recommendation please?


    laureano Adriano

    Wednesday, February 15, 2017 5:37 PM
  • Hi,

    SharePoint 2010 people picker is different from SharePoint 2013. You can try the following code:

    <script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
    
    <script type="text/javascript">
    
    $(function(){
    
                invokeAfterEntityEditorCallback(onPeoplePickerFieldSet);
    
    });
    
    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);
    
            }
    
        }
    
    };
    
    function onPeoplePickerFieldSet(result, ctx){
    
                alert("inside OnValueChangedClientScript");}
    
    </script>
    

    By the way, you can post in SharePoint 2010 forum next time :)

    Thanks,

    Dean Wang


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Thursday, February 16, 2017 9:16 AM
    Moderator
  • Thank you so much for your answer and comments. Itwas just what I was looking for.

    Works perfect for me on my form with my three peoples pickes. But is there any way to can only send the alert when the user is introduced to the people picker GP? and not send the alert when the user is introduced in the other peoples picker?


    laureano Adriano

    Friday, February 17, 2017 12:04 AM