Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DynamicForm - Error on save when clearing person from Person or Group field and leaving it blank. #1578

Closed
Fantasticles opened this issue Jul 3, 2023 · 7 comments
Labels
status:fixed-next-drop Issue will be fixed in upcoming release. type:bug
Milestone

Comments

@Fantasticles
Copy link

Thank you for reporting an issue, suggesting an enhancement, or asking a question. We appreciate your feedback - to help the team understand your
needs please complete the below template to ensure we have the details to help. Thanks!

Please check out the documentation to see if your question is already addressed there. This will help us ensure our documentation is up to date.

Category

[ ] Enhancement

[x] Bug

[ ] Question

Version

Please specify what version of the library you are using: [ 3.14.0 (also tried latest beta) ]

If you are not using the latest release, please update and see if the issue is resolved before submitting an issue.

Expected / Desired Behavior / Question

When removing a person from a "Person or Group" field with 'Allow multiple selections' set to no it should let me save.

Observed Behavior

When clearing the contents of a "Person or Group" field and when 'Allow multiple selections' is set to 'No' on clicking 'Save' the following error pops up:

Error making HttpClient request in queryable [400] ::> {"odata.error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"A node of type 'StartArray' was read from the JSON reader when trying to read a value of a property; however, a 'PrimitiveValue' or 'StartObject' node was expected."}}}

It is only happening on the "Person or Group" field and if I allow multiple selections on that field it works correctly. This is happening for every web part and form customizer I have created that uses DynamicForm with a "Person or Group" field. If the field has always been empty it saves fine, it's only when there is a person in that field and then that person is removed and the field is blank and saved again.

Steps to Reproduce

As soon as the "Person or Group" fields setting is set to not allow multiple selections and then the field is left blank when it previously wasn't, on save it will produce the error. Tested on web parts and field customizers, on lists migrated from on premises SharePoint and fresh lists created in SharePoint online.

Thanks!

@ghost
Copy link

ghost commented Jul 3, 2023

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

@ghost ghost added the Needs: Triage 🔍 label Jul 3, 2023
@github-actions
Copy link

github-actions bot commented Jul 3, 2023

Thank you for submitting your first issue to this project.

@NishkalankBezawada
Copy link
Contributor

I found a solution, will be creating a PR on this by tomorrow.

@NishkalankBezawada
Copy link
Contributor

Hello @Fantasticles

I have created a new pull request resolving the reported issue. Below is the solution,

Solution for Issue #1578

When the user is updating the people picker column, for a single user, Dynamic form is throwing error while saving the list item. The issue occurs at method onSubmitClick

The object formed with an empty user and is being submitted to update the item

          else if (fieldType === "User") {
            objects[`${columnInternalName}Id`] = val.newValue;
          }             

And the error is caught here,

let newETag: string | undefined = undefined;
if (listItemId) {
  try {
    const iur = await sp.web.lists.getById(listId).items.getById(listItemId).update(objects, this.state.etag);
    newETag = iur.data['odata.etag'];
    if (onSubmitted) {
      onSubmitted(iur.data, this.props.returnListItemInstanceOnSubmit !== false ? iur.item : undefined);
    }
  }
  catch (error) {
    if (onSubmitError) {
      onSubmitError(objects, error);
    }
    console.log("Error", error);
  }

By validating the null check as below, the issue is resolved.

else if (fieldType === "User") {
    objects[`${columnInternalName}Id`] = val.newValue.length === 0 ? null : val.newValue;
}

I have also corrected a spelling mistake at onSubmitClick

from, 'val.newValue.lenght'

          else if (fieldType === "UserMulti") {
            objects[`${columnInternalName}Id`] = { results: val.newValue.lenght === 0 ? null: val.newValue };
          }

To, 'val.newValue.length' as below.

else if (fieldType === "UserMulti") {
            objects[`${columnInternalName}Id`] = {
              results: val.newValue.length === 0 ? null : val.newValue,
            };
          }

Thanks,
Nishkalank Bezawada

@Fantasticles
Copy link
Author

@NishkalankBezawada Thanks heaps for your great work! (Relieved that it wasn't something I was doing wrong)

@joelfmrodrigues joelfmrodrigues added status:fixed-next-drop Issue will be fixed in upcoming release. type:bug and removed Needs: Triage 🔍 labels Jul 6, 2023
@joelfmrodrigues joelfmrodrigues added this to the 3.15.0 milestone Jul 6, 2023
@joelfmrodrigues
Copy link
Collaborator

Thanks both.
The PR to fix this issue has been merged and the fix should be in the beta release in a few minutes

@joelfmrodrigues
Copy link
Collaborator

New release just published, closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:fixed-next-drop Issue will be fixed in upcoming release. type:bug
Projects
None yet
Development

No branches or pull requests

3 participants