Bug #96424
closedResetting form validators does not work as expected
100%
Description
Problem¶
If form validators are to be reset by calling \TYPO3\CMS\Form\Domain\Model\Renderable\AbstractRenderable::setOptions()
with second parameter $resetValidators = false
, it seems that not all validators are actually reset if there is more than one validator defined. This is because the underlying SplObjectStorage
does not operate as someone might expect in combination with foreach
.
Steps to reproduce¶
Generate a basic form with an element and a variant such as follows:
- identifier: element-1
type: Text
# ...
- identifier: element-2
type: Text
# ...
validators:
- identifier: NotEmpty
- identifier: EmailAddress
variants:
-
identifier: variant-1
condition: 'formValues["element-1"] == "some-value"'
validators: []
Now in the Frontend, set the value of element 1 to some-value
and submit the form. You should receive a validation error for element 2, even though all validators should be removed in this case.
Solution¶
A simple solution would be to clone the validators when iterating and performing detaches (as suggested here).
For this, compare the result of the underlying code:
- Current code: https://3v4l.org/8Bnd3 (fails)
- Variant with
clone
: https://3v4l.org/imCXv (works)