Project

General

Profile

Actions

Bug #101438

open

Having a validator in formElementsDefinition.Element and subsequent in its formEditor.predefinedDefaults.validators executes it twice with different options

Added by S P over 1 year ago. Updated over 1 year ago.

Status:
New
Priority:
Should have
Assignee:
-
Category:
Form Framework
Target version:
-
Start date:
2023-07-25
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
12
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

I wrote a custom form element that should force some validation that is neither removable in the Backend editor nor in the YAML file, but provides some options.

So I added

formElementsDefinition:
    MyElement:
        validators:
            # force the validation in the runtime, make it non-removable even via concrete form YAML
            - identifier: MyValidator
        formEditor:
            predefinedDefaults:
                validators:
                    # force the rendering, make it non-removable in the editor as well, so that editor always stays in control over the options
                    - identifier: MyValidator

The predefined defaults must be there so that the validator is rendered into the form editor (it must be rendered there because it has options to be set by the backend users). And the element validators section is there so that the validator is always foreced and can not be removed by the editing the form YAML file.

BUG: But this causes the validator to be instantiated and executed twice. Once with default options and once with the options entered in the form editor.

For now I have removed the form defintion validator, leaving only

formElementsDefinition:
    MyElement:
        formEditor:
            predefinedDefaults:
                validators:
                    - identifier: MyValidator

because this always renders the validator into the form editor and saves it into the YAML file.

But now it is possible to edit the concrete form YAML file and just remove the validator there. Then it is not executed at all (because the element defintion does not have it anymore)! But I need to force it under all costs.

I think this is an architectural bug. Validators with the same identifier should be "singleton" to a unique form field, using the option values as entered in the editor (form YAML) with fallback to the defaults in the defintion! That's what I totally intuitively expected when I wrote my custom field - but it turned out to be not the case.

Actions

Also available in: Atom PDF