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.
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.
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
The case is for validating a ValueObject in a <f:form>.
- Status changed from New to Needs Feedback
Could you clarify why you don't use property
instead of name
in <f:form.textfield />
?
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.
Also available in: Atom
PDF