0

I have a working people picker on a .Net Create, I followed the following stack overflow to get that working: How to get input values from mgt-people-picker when a FORM is submitted

...the mgt component documentation leaves a lot to be desired.

In my form I have the following:

<mgt-people-picker selection-mode="single">
    <template data-type="selected-person">
        <input type="hidden" value="{{person.userPrincipalName}}" name="selectedPerson" id="transmissionEstimator" />
        @if (CREATE CONDITION)
        {
            <mgt-person view="oneLine" person-details="{{person}}" fetchImage=true></mgt-person>
        }
        else
        {
            var selectedPerson = @Html.Raw(Json.Encode("emailstringfrom@backend.com"));
            <mgt-person view="oneLine" person-details="{{person}}" defaultSelectedUserIds=@selectedPerson fetchImage=true></mgt-person>
        }
    </template>
</mgt-people-picker>

In my backend Save function I have the following:

Request.Form["selectedPerson"];

So I'm able to add users in the CREATE condition, but when I trigger the edit version of the form (confirmed via breakpoint), I expect to see the user that was selected as the default selected user on the component.(Their email was stored and is now coming from the database)

Looking at the element (Dev Tools - F12) I see that the property has been populated! (I removed the email for privacy reasons. But it is in in the format {["user@domain.com"]} and is being passed in via ViewModel to defaultSelectedUserIds

From Console after triggering edit form

And still no dice...

Some more things I've tried also tried these formats using the attribute version of default-selected-user-ids

  1. [{"user@domain.com"}]
  2. {"user@domain.com"}
  3. "user@domain.com"

Is my formatting incorrect? Am I not passing the value in correctly?

Any help would be greatly appreciated!

1 Answers1

0

The mgt-person component doesn't currently support default-selected-User-ids https://learn.microsoft.com/en-us/graph/toolkit/components/person#properties, that is actually only supported on the mgt-people-picker component.

Instead try the person-query attribute to pass the email of the user to mgt-person, see the final example on the playground here: https://mgt.dev/?path=/story/components-mgt-person--more-examples

Nic Vogt
  • 261
  • 1
  • 6
  • this might be better to handle on our repository for visibility and ease of posting, Can you open the issue with the screenshots here: https://github.com/microsoftgraph/microsoft-graph-toolkit/issues/new/choose – Nic Vogt Apr 02 '21 at 20:22
  • Got this working, with the mgt-person component on edit, which isn't ideal. but I figured out that I was not passing my viewmodel properties to jquery correctly. I had to make a hidden input on the form where I pass in the viewmodel property holding the user's email Then passed that value into the mgt-person component if there was a user to show, otherwise I display the people-picker. – David Arias Apr 08 '21 at 23:43