none
Clear PeoplePicker value in List NewForm.aspx RRS feed

  • Question

  • Hi,

    In List NewForm.aspx page, i have PeoplePicker control, dropdown and few text fields.

    I have to load values in all fields based on dropdown changed event using jquery, i completed this part to load all fields.

    When user changed the dropdown value again and again, the peoplepicker control value get append. i tried to clear its value when dropdown changed event but it not works. Here is the code i have used:

    $("input[title='Owner']").val("");
            var _PeoplePicker = $("div[title='Owner']");
           var _PeoplePickerTopId = _PeoplePicker.attr('id');
           
           var _PeoplePickerEditer = $("input[title='Owner']");
    //$(_PeoplePickerEditer).empty();

           _PeoplePickerEditer.val("test user");
           var _PeoplePickerOject = SPClientPeoplePicker.SPClientPeoplePickerDict[_PeoplePickerTopId];
           _PeoplePickerOject.AddUnresolvedUserFromEditor(true);  

    Thanks in advance...

    Friday, July 11, 2014 4:06 AM

Answers

  • Hi,

    Please use the following code to delete the user list from the people picker

    var spPeoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict[_PeoplePickerTopId]; // Get the instance of the People Picker from the Dictionary
    if (spPeoplePicker) {
    var ResolvedUsersList = $(document.getElementById(spPeoplePicker.ResolvedListElementId)).find("span[class='sp-peoplepicker-userSpan']");
    $(ResolvedUsersList).each(function (index) {
    spPeoplePicker.DeleteProcessedUser(this);
    });
    }

    Please mark it answered if resolved.

    • Marked as answer by Syed Musthafa Friday, July 11, 2014 10:05 AM
    Friday, July 11, 2014 5:09 AM

All replies

  • Hi,

    Please use the following code to delete the user list from the people picker

    var spPeoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict[_PeoplePickerTopId]; // Get the instance of the People Picker from the Dictionary
    if (spPeoplePicker) {
    var ResolvedUsersList = $(document.getElementById(spPeoplePicker.ResolvedListElementId)).find("span[class='sp-peoplepicker-userSpan']");
    $(ResolvedUsersList).each(function (index) {
    spPeoplePicker.DeleteProcessedUser(this);
    });
    }

    Please mark it answered if resolved.

    • Marked as answer by Syed Musthafa Friday, July 11, 2014 10:05 AM
    Friday, July 11, 2014 5:09 AM
  • Thank you so much Mokhtar... its working for me
    Friday, July 11, 2014 10:06 AM
  • same for me, thanks !

    Blog Sharepoint : www.paslatek.net Twitter : @LimozinLionel

    Friday, August 29, 2014 11:25 AM
  • Thank you!
    You pointed me to the right direction here
    Thursday, April 16, 2015 2:13 PM
  • You are my hero.  Thank you for this.  Why is this method not documented anywhere?!
    Tuesday, September 4, 2018 4:05 AM