Generic usage of validation.ifHasErrors viewhelper possible?

There is a partial Address/FormFields.html in one of our projects in which I would like to add class="error" to invalid argument properties’ <label> elements:

<label for="street" class="{f:validation.ifHasErrors(for: 'person.address.street', then: 'error')}">Street</label>

As far as I can see I have to use the full property’s path (person.address.street) in the for attribute of this viewhelper.

As Address (and the above mentioned partial) is used for various objects (Person, Organisation, Shop, etc.) the names of the submitted request arguments differ: person, organisation, shop, etc. Therefore person.adress.street does only work if the request argument is person.

Is it possible to use the validation.ifHasError viewhelper in a generic way so that it does not matter what the name of the argument is? If not, how would you work around this limitation?

To know the validation results we need the full name of the argument. Usually my partials require to set the “prefix” or path so I basically append to that. That way every template can set the matching prefix.

1 Like

Elegant way to solve this “problem”. Works like a charm. Thx! :smile: