Project

General

Profile

Actions

Bug #86829

open

The errorClass doesn't work for non formObject fields

Added by Bill Dagou about 6 years ago. Updated about 1 year ago.

Status:
Needs Feedback
Priority:
Should have
Assignee:
-
Category:
Fluid
Target version:
-
Start date:
2018-11-02
Due date:
% Done:

0%

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

Description

The code is something like below.

<f:form action="update" object="{object}" objectName="object">
    <f:form.textfield class="form-control" name="other[field]" errorClass="is-invalid" />
</f:form>

When I set the validation like NotEmpty for $other.field, and submit the form keeping the field empty, the class is-invalid is never added.

Actions #1

Updated by Bill Dagou about 6 years ago

My fix was

    protected function getMappingResultsForProperty()
    {
        if ($this->isObjectAccessorMode()) {
            $originalRequestMappingResults = $this->getRequest()->getOriginalRequestMappingResults();
            $formObjectName = $this->viewHelperVariableContainer->get(
                \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class,
                'formObjectName'
            );
            return $originalRequestMappingResults->forProperty($formObjectName)->forProperty($this->arguments['property']);
        } elseif ($this->arguments['name']) {
            $originalRequestMappingResults = $this->getRequest()->getOriginalRequestMappingResults();
            return $originalRequestMappingResults->forProperty(str_replace(['[', ']'], ['.', ''], $this->arguments['name']));
        } else {
            return new \TYPO3\CMS\Extbase\Error\Result();
        }
    }

in \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper

Actions #2

Updated by Bill Dagou about 1 year ago

The case is for validating a ValueObject in a <f:form>.

Actions #3

Updated by Simon Praetorius about 1 year ago

  • Status changed from New to Needs Feedback

Could you clarify why you don't use property instead of name in <f:form.textfield />?

Actions #4

Updated by Bill Dagou about 1 year ago

Yes. Generally it's for validating a ValueObject, especially in editAction($domainObject, $valueObject).

In some of my projects, I need to validate the state in Address or a hex color code in Color, which are all ValueObjects. After I set all the validations up, the logic works and the code will not go to the persist part, but the errorClass is never added to the HTML element because of the current getMappingResultsForProperty() function.

That's why I'm asking for this change. Or, maybe I'm using the ValueObject in a wrong way.

Actions

Also available in: Atom PDF