Feature: #85070 - New ViewHelper f:form.hasErrors 

See forge#85070

Description 

A new condition ViewHelper <f:form.hasErrors> tells whether a property of the current form has validation errors:

<div class="{f:form.hasErrors(for: 'blog.title', then: 'has-error')}">
    <f:form.textfield property="title" />
</div>
Copied!

It extends the usual condition ViewHelper base class, so <f:then> and <f:else> work as well:

<f:form.hasErrors for="blog.title">
    <f:then>The title has at least one validation error.</f:then>
    <f:else>The title is fine.</f:else>
</f:form.hasErrors>
Copied!

Validation results could already be read with <f:form.validationResults> , but only as a block: that ViewHelper assigns a variable and renders its children, so it cannot be used inline inside an attribute. Setting a CSS class on a wrapping element therefore meant wrapping the markup in a block and nesting an <f:if> inside it.

The second reason is less obvious. \TYPO3\CMS\Extbase\Error\Result offers hasErrors() , which also reports errors of sub properties, but that method cannot be reached from a template: Fluid resolves {results.errors} to getErrors() , which only returns the errors of that very node. A template checking {results.errors} for for="author" therefore sees nothing when the error sits on author.email . The new ViewHelper evaluates hasErrors() and reports errors of sub properties as well.

The for argument is required and must be a non-empty property path. Any other value raises an exception, so an unresolved or mistyped variable cannot silently match the whole form.

Impact 

Templates can mark up the surroundings of a form field without wrapping them in a block:

<div class="form-group {f:form.hasErrors(for: 'email', then: 'error')}">
    <label>Email</label>
    <f:form.textfield property="email" />
</div>
Copied!

For the error objects themselves, <f:form.validationResults> remains the ViewHelper to use. The error class of a single form field is still set by the errorClass argument of that field, which needs no extra ViewHelper.