Project

General

Profile

Actions

Bug #96424

closed

Resetting form validators does not work as expected

Added by Elias Häußler almost 3 years ago. Updated about 2 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Form Framework
Target version:
-
Start date:
2021-12-21
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
11
PHP Version:
Tags:
Complexity:
easy
Is Regression:
Sprint Focus:
Remote Sprint

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:


Related issues 1 (0 open1 closed)

Has duplicate TYPO3 Core - Bug #97028: Validators not removed when variant appliesClosed2022-02-24

Actions
Actions

Also available in: Atom PDF