0

I'm doing some manipulation of my new and edit forms using javascript and jQuery. I'm able to find all the people pickers on the page with the following selector

var $pickers = $('div[title="People Picker"]');

but I haven't been able to figure out how to tell if each picker is a single person or multiperson. These are the old-style people pickers not the client-side pickers. I'm looking through the html and not seeing anything that would directly indicate which kind of people column the picker is for.

The multipicks do have a line that says Enter users separated with semicolons. so I could check for that, but that seems pretty sketchy.

I know that the new client people pickers have a dictionary object on the page and that can be used to determine if a client-side people picker is single or multiple by

SPClientPeoplePicker.SPClientPeoplePickerDict["<name>_TopSpan"].AllowMultipleUsers

Is anything similar for the old style people pickers. I've also looked through the entityeditor.js file, but can't find anything to help. Any tips on how to do this properly?

1

It doesn't appear that there will be anything in the rendered DOM from what I can gather. What you could do is fire off a GetList request via SPServices and parse through the field elements. It clearly states in the person group fields in a couple places if it accepts multiple values, Type and Mult. Some XML from a GetList call, the first is a single selection and the second is a multiple selection:

<Field 
    Type="User" 
    DisplayName="single" 
    List="UserInfo" 
    Required="FALSE" 
    EnforceUniqueValues="FALSE" 
    ShowField="ImnName" 
    UserSelectionMode="PeopleOnly" 
    UserSelectionScope="0" 
    ID="{bde6ed18-5177-419d-8b11-19f4e1a46f51}" 
    SourceID="{cac5800a-4b47-4f62-a4d9-25b48d3bb2e1}" 
    StaticName="single" 
    Name="single" 
    ColName="int1" 
    RowOrdinal="0"/>

<Field 
    Type="UserMulti" 
    DisplayName="multiple"
    List="UserInfo" 
    Required="FALSE" 
    EnforceUniqueValues="FALSE" 
    ShowField="ImnName" 
    UserSelectionMode="PeopleOnly" 
    UserSelectionScope="0" 
    Mult="TRUE" 
    Sortable="FALSE" 
    ID="{5ccce6e6-0e2d-4c3e-9460-124a1ac828a5}" 
    SourceID="{cac5800a-4b47-4f62-a4d9-25b48d3bb2e1}" 
    StaticName="multiple" 
    Name="multiple" 
    ColName="int2" 
    RowOrdinal="0"/>

SPServices does offer a nice function to work with people picker fields that might sway your decision to incorporate the library, http://spservices.codeplex.com/wikipage?title=%24%28%29.SPServices.SPFindPeoplePicker. People picker fields are just ugly to work with in general.

  • Thanks. I'm trying to avoid having to add SPServices and/or make a network call to find this out for every entry on the page. It seems there should be a way to know from the page – Rothrock Mar 24 '16 at 18:28
  • It is only 1 call, you get the entire field collection back in the response. There doesn't appear to be any other way unless you want to use your sketchy approach. This ensures you get the right data. – Eric Alexander Mar 24 '16 at 18:34
  • I'm giving this a go with the REST api (which I prefer to SPServices) but now I don't see how to connect up the people picker with the column data. I thought the guid for the column might be used as a selector, but it isn't on the page. – Rothrock Mar 24 '16 at 19:26
  • It should be injecting a comment into the HTML that you might be able to leverage like so <!-- FieldName="single" FieldInternalName="single" FieldType="SPFieldUser" --> SPServices does have a handy function to get to People Picker fields, spservices.codeplex.com/… – Eric Alexander Mar 24 '16 at 19:47
  • Nope there isn't anything like that in the html. We are using on-prem SP 2013. I am familiar with SP Services, but we are trying to move away from that. I'm able to find all the people pickers on the page, but I don't know how to connect up the xml/json returned about the list columns to the specific people picker on the page. If there is only one it is easy, but after that.... – Rothrock Mar 24 '16 at 20:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.