See parent issue: https://www.drupal.org/project/webform/issues/3517077

Problem/Motivation

The fix that landed for #3517077 doesn't close the actual gap that causes the error message, and the bug is still reproducible on 6.3.0-rc2, including with plain core element types, no contrib/custom elements involved.

Reordering form elements and then deleting a different element before clicking "Save elements" can still fail with:

The submitted value [X] in the Weight for [Some Element] element is not allowed.

The element named in the error is often one that was never dragged at all, commonly the topmost row in the table.

Steps to reproduce

  1. Create a form with 4 elements, e.g. textfields.
  2. Move the third element to second position (one step up), do not save.
  3. Delete the now-third element.
  4. See error message.

What I think is happening

The fix in the parent issue (changing $delta = count($elements); to $delta = count($elements) + 1; in WebformUiEntityElementsForm::buildForm()) does not work because:

core/misc/tabledrag.js's order action does not only change the weight of the dragged element, but reserializes weights for every sibling element too, starting from the most negative value.

So lets say I have four elements in a form. The count($elements) is 4 which means $delta is 5. I drag one element to another position, at which point the first element gets weight -5 (-$delta per Drupal core). Then I delete another element, so count($elements) becomes 3 and $delta 4, but the weight of the first element is still -5, which is out of the allowed range that now starts from -4 upwards.

That's why the error is shown.

Proposed resolution

Add a custom #process callback for weight element that checks the actual submitted value and adds that to #options if it's not there already. See what Weight::processWeight() already does with #default_value, but apply it to the raw submitted #value instead.

Issue fork webform-3612678

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