Problem/Motivation

When validating fields of type webform_users with validateWebformUsers(), the value is set incorrectly, which causes issues and lost data when saving multiple values with one of them being invalid.

In https://git.drupalcode.org/project/webform/-/blob/6.3.x/src/Element/Webf... the value is set like this:

    $element['#value'] = $uids;
    $form_state->setValueForElement($element, $uids);

The $form_state->setValueForElement($element, $uids) should be sufficient, whereas the former is not needed at all. In this context $uids is an array of strings, e.g. ['4', '8', '16'], so $element['#value'] = $uids is incorrect, as the value of the field should be an array of user entities.

$form_state->setValueForElement($element, $uids) takes care of that, so there is no need to use the former at all.

Steps to reproduce

See attached video also.

  1. Go to /admin/structure/webform/manage/XXX/access.
  2. Add valid user to one of the Users fields, save.
  3. Add invalid value to the same field, save.
  4. The invalid value is gone from the field.
  5. The valid value is turned in to a user ID and is now also considered invalid.

Proposed resolution

Remove $element['#value'] = $uids as redundant. This way, when saving the field with a valid AND an invalid value, the valid value would be kept as a user entity (as it should), and the invalid value would also be shown with the error message included.

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
webform-(2).mp4704.88 KBtuuuukka

Issue fork webform-3554702

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

tuuuukka created an issue. See original summary.

tuuuukka’s picture

Status: Active » Needs review

liam morland made their first commit to this issue’s fork.

jrockowitz made their first commit to this issue’s fork.

jrockowitz’s picture

Status: Needs review » Fixed

Change makes perfect sense.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.